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) !!}
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.
Im working in PHP Laravel to build an RSS FEED READER
I have read the XML file and it displays the title, description and link.
But the description contains image which i don't know how to display as an image.
Now the image part comes in html format as shown below:
Instead i want it to be displayed like this:
Here is my html code where the rss feed content display happens:
#foreach ($feed->item as $item)
<tbody>
<div class="card">
<div class="card-header">
{{ $item->title}}
</div>
<div class="card-header">
{{ $item->thumbnail}}
</div>
<div class="card-body">
{{$item->description}}
</div>
</div>
</tbody>
#endforeach
Can somebody please help me with this.
Thanks in advance.
You have HTML in your $item->description using the double Mustache{{ }} You are telling Laravel escape the data.
To render the HTML, you need to use instead {!! !!}
<div class="card-body">
{!! $item->description !!}
</div>
You can see more in the doc here: https://laravel.com/docs/7.x/blade#displaying-data
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() }}
The problem
When rendering a view with blade, I call a function which generate a form (with the Laravel Form Builder). This all works like a charm! For my project I need a custom form and a custom form field. After some puzzeling also a success, still no problem huray! Now I need a way to push a link to a list in my parent view.
parentview.blade.php
<div class="panel-body">
<ul class="wizard_steps">
#stack('category_steps')
</ul>
{!! form($form) !!}
</div>
customForm.blade.php
#push('category_steps')
<li>
<a href="#{{$options['real_name']}}">
<span class="step_no"></span>
<span class="step_descr">
<?php if ($showLabel && $options['label'] !== false && $options['label_show']): ?>
{{ $options['label'] }}
<?php endif; ?>
</span>
</a>
</li>
#endpush
<div id="#{{$options['real_name']}}">
{!! form_rest($options['field_form']) !!}
</div>
And here is the problem. The list item is not added to the stack in the parent.
Steps to reproduce
I've narrowed the problem down to {!! form($form) !!} that. So to reproduce:
make a file home.blade.php and paste text:
home.blade.php
<?php
/** #return string */
function test()
{
return view('test')->render();
}
?>
#stack('moreTest')
{!! test() !!}
now the file test.blade.php and paste text:
test.blade.php
#push('moreTest')
<p>This is not pushed</p>
#endpush
Anybody an idea how to fix this problem?
Thanks!
P.S.:Working with laravel 5.4.23
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.