I am trying to set a custom HTML attribute name using twig, trying to achieve this:
<div age="24"> Something </div>
This is my code:
{% set custom_age_attribute= "age" %}
<div {{custom_age_attribute}}="24"> Something </div>
But the twig code is not rendering and getting this:
<div {{custom_age_attribute}}="24"> Something </div>
Is there any way to make it work?
Related
I pass into twig template variable that contains html code. When I print it I get something like that:
<div class="links"> <span class="logo"></span> homepage page 1 page 2 page 3 </div>
How do i make the code look more readable? Like this:
<div class="links">
<span class="logo"></span>
homepage
page 1
page 2
page 3
</div>
If you want to display the htmlas is for a code snippet I'd suggest you just wrap <pre> around it.
<pre>{{ html }}</pre>
demo
If you just want to preserve newlines and tabbing you could wrap the var with div and set the white-space to pre
<style>
div.pre {
white-space: pre;
}
</style>
<div class="pre">{{ html }}</div>
The source HTML is displayed exactly as you pass it in. One way I can think of to fix this specific issue is by using a solution like https://stackoverflow.com/a/34556900/4646470 to format the HTML and create a Twig filter/function 1 to handle it in Twig templates.
I am giving the sample example solution to your questions. I hope it helps you.
{{ title }} {{ entity_print_css }} {{ content }}
Sample node--article--pdf.html.twig
{{ content.field_name }} {{ content.body }} {{ label }} {{ content.field_name.0.value }}
I want to display data from database (using PHPMYADMIN). The data which I want to display stored using ng2-ckeditor (Angular 6). So when it gives result it also shows the html tags, which I don't want. How do I get my result without displaying HTML tags?
This is for displaying in html page
(and newsArray is type Object)
which is displaying data but with html tags
<div *ngFor="let item of newsArray">
<div class="panel-body">
{{item.details}}
</div>
</div>
result given by this is:
<p>hello</p>
but expected result:
hello
you can use [innerHtml] property on the div
<div *ngFor="let item of newsArray">
<div class="panel-body" [innerHtml]='item.details'>
</div>
</div>
You can replace your result like this:
getText() {
return this.data.replace(/<[^>]*>/g, '');
}
This will replace all your html tags and keep only the blank text.
See my stackblitz demo
I am setting up a simple CMS and I am using a Textarea (Froala to be exact) to render the HTML content of each page that's generated via database. The textarea can display the html with no problems. However, the blade template isn't executing. It's just in plain text. How can I make sure blade executes correctly? I need it mainly for links.
For an example. I have a form element written in blade:
{{ Form::text('name')}}
It should display like so on my page:
<input name="name" type="text">
However, it's just displaying like this:
{{ Form::text('name')}}
EDIT: here is my pages.blade.php file if they may help with figuring it out.
#extends('layouts.main')
#section('main_content')
<section class="mainContent">
<div class="row">
<h1 title="{{ $pages->title }}">{{ $pages->title }}</h1>
{{ $pages->body }}
</div>
</section>
#stop
There is no out-of-the-box way to do that. Blade templates are compiled only from files.
But you can take look at
Flynsarmy/laravel-db-blade-compiler if you want to compile Blade from Eloquent model
or
TerrePorter/StringBladeCompiler if you want to compile Blade from strings.
I am trying to print a html tag in django template using safe option in django templates.
I am using it like below.
{{ message|safe }}
It works fine as long as I have only one tag ,
for example If I have to print below, it works fine.
<div class="message">data</div>
But If I have another tag inside div , it is not generated as raw html, rather it is generated as below.
<div class="message"><img src="/media//uploads/Capture_16.PNG" /></div>
I would like it to be generated as
<div class="message"><img src="/media//uploads/Capture_16.PNG" /></div>
What options do I have to achieve this ?
EDIT
Below is the original message without using safeor any kind of escaping.
<div class="message">data</div>
<div class="message"><img src="/media//uploads/Capture_16.PNG" /></div>
I've seen some posts saying you can only pass literal strings to Jekyll's front matter include statement like so:
{% include mypage.ext %}
However, I have the following HTML layout for pretty much every page:
<section id="feature">
<div class="container_12">
<div class="grid_12 alpha omega">
{% include myfile.ext %}
</div>
</div>
</section>
<section id="main">
<div class="container_12">
<div class="grid_12 alpha omega">
{{ content }}
</div>
</div>
</section>
This would be painful to have to include in every single page in order to achieve the layout I'm looking for. The included file would be relevant to the current page, so I was hoping someone knew of some kind of way to do this. Of course it'd be something along the lines of:
{% include {{page.file}} %}
I've seen some other posts saying this just can't happen though.
So, I just want to be able to dynamically load includes in Jekyll.
Edit: https://github.com/mojombo/jekyll/issues/176
This will be perhaps possible when that issue will be fixed with the pull request #1495 which propose exactly what you are looking for : {% include {{page.file}} %}
This is currently intentionally not possible, as the maintainers of Jekyll don't want the project to get too dynamic. You can read this comment & thread for a bit of background. The suggestion that qrush (the maintainer) gives is to use rails or sinatra. Probably not the answer you're looking for, but that's the current status.
If you want to use a plugin, there's one that will let you do this here