I have <p><strong>Some Body Lement Some Body Lement</strong></p> In database. I want to print in blade as html. but it prints as text
In my blade I have
#foreach( $articles as $article )
<div class="recommended-info"><h3>{{ $article['title'] }}</h3></div>
{{ $article['body'] }}
#endforeach
If you don't want to escape the HTML, then you need to use the {!! !!} syntax. Example:
#foreach( $articles as $article )
<div class="recommended-info"><h3>{{ $article['title'] }}</h3></div>
{!! $article['body'] !!}
#endforeach
Source: http://laravel.com/docs/5.1/blade
Section: "Displaying Unescaped Data".
By default, Blade {{ }} statements are automatically sent through PHP's htmlentities function to prevent XSS attacks.
Note: Be very careful when echoing content that is supplied by users of your application. Always use the double curly brace syntax to escape any HTML entities in the content.
Related
I want to put together a menu and get an icon dynamically.
the result i want is something like this:
Database table:
code:
<div class="card card-dashboard-eight">
<label class="main-content-label mb-1">Categoryes</label>
<span class="d-block mg-b-20 text-muted">Stores All</span>
<div class="list-group">
#foreach($tipos as $tipo)
<div class="list-group-item">
{{$tipo->icono }}
<p>{{$tipo->tipo }}</p>
</div>
#endforeach
</div>
</div>
but it prints the label not the icon
What should I do to show my icons?
I dont know the template engine you are using, but it seems to escape the html chars. maybe it just works by removing the double brackets ("{$tipo->icono}" instead of "{{$tipo->icono }}").
But for app-design reasons: i'd suggest to store just the type (or class) in the database. not an html-tag. meaning: the column "icono" should just contain f.e. "glass-martini" - instead of a complete html-tag. put the html-stuff in your template and add the class from your column there.
You have to use {!! !!} to display the raw unescaped HTML of your icon:
{!! $tipo->icono !!}
This way it doesn't get escaped with htmlspecialchars.
Basically {{ $var }} will be compiled to <?php htmlspecialchars($var); ?> and {!! $var !!} to <?php echo $var; ?>.
See the docs on how to display data in Blade templates for more information.
What is the correct way to call the "Links" function after this "Foreach"?
I don't know how to handle the variable to put in function.
#inject('usuarios', 'App\User')
#foreach($usuarios->getIndicados() as $user)
#endforeach
<div class="row">
<div class="col-12 text-center">
{{ $usuarios->getIndicados()->links() }}
</div>
</div>
Maybe it's just an editing error, but in your output the -tags don't seem to be closed again. Also, there should be no space like < a> at the beginning of the tag. And < a hr_ef= ... is obviously wrong.
In order to style them, you can add a class attribute to the tags while building the string and do the style-stuff in css.
This is what laravel document provides. You need to add links in the collection.
<div class="container">
#foreach ($users as $user)
{{ $user->name }}
#endforeach
{{ $users->links() }}
Okay so I have the following (multiple times) in my blade template:
{{ Auth::user()->settings['font'] == null ? "<span class='fa fa-check'></span>" : false }}
However it doesnt render the span statement, it simply prints it out. I've read elsewhere that to render HTML in a blade template I need to use {!! <span></span> !!} but how can I do that within a shortcut IF statement?
The {{ $thing }} syntax escapes the content passed to it via the e() helper. You can use the following alternative syntax: {!! $thing !!}
This syntax works the same as the first one so you can use your ternary condition too. The following will print nothing if the condition is not met.
{!! Auth::user()->settings['font'] == null ? "<span class='fa fa-check'></span>" : '' !!}
Alternatively with #if:
#if(Auth::user()->settings['font'] == null)
<span class='fa fa-check'></span>
#endif
I want to put a line break into a blade report.
I know there is the {!! !!} tags to escape the html tags, but in my situation I have a long string coming in at {{$row[$colField]}} so it already within {{ }} tags.
The way I tried it would have appeared like {{ randome text {!! <br/> !!} }}.
Is there any other way to do this perhaps.
#foreach($fieldList as $field)
#if ($header->group == $field->group)
<?php $colName = $field->columnname ?>
<?php $colField = $field->columnfield; ?>
<?php $fieldGroup = $field->group; ?>
#if ($colName != $fieldGroup)
<span class="titleSpan" style="white-space: nowrap; font-weight: bold">{{ $colName=='Age'?'':$colName.':' }} </span>
#endif
{{$row[$colField]}}<br>
#endif
#endforeach
The curly brace blade tags are for echoing values, they don't do anything else and you cannot nest them in the way you're trying to in your example. You can find information about these tags in the Blade documentation, but in summary:
The double curly brace tag means echo this value and escape it, e.g:
{{ $row[$colField] }}
compiles to:
<?php echo e($row[$colField]); ?>
A curly brace with 2 exclamation marks means echo this value without escaping it, e.g:
{!! $row[$colField] !!}
compiles to:
<?php echo $row[$colField]; ?>
If you would like for a line break (<br/>) to appear somewhere within the value of $row[$colField] then you must transform that value before outputting it. There are functions, like nl2br that can replace new lines with line breaks, so you could for example do this:
{!! nl2br($row[$colField]) !!}
Which would compile to:
<?php echo nl2br($row[$colField]); ?>
So if the value of $row[$colField] is:
Hello world
This is another line.
Then that code would output:
Hello world</br>
This is another line.
That said your question is unclear so if this information does not help then please rewrite your question to clearly communicate what you're trying to achieve, i.e: include an example of your input and an example of your desired output.
I have the following blade template in laravel
<h3>Category</h3>
<div class="leftBoxBody">
<ul class="cat-link">
#foreach($categories as $category)
<li>{{Html::link('category/'.$category->id, $category->name)}}</li>
#endforeach
</ul>
</div>
But its being generated into raw text instead of html tags output:
Why is this ?
It is happening because of escaping. Try with -
{!! Html::link('category/'.$category->id, $category->name) !!}