Reputation: 135
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><a href="{{url('/category/type/'.$tipo->tipo)}}">{{$tipo->tipo }}</a></p>
</div>
@endforeach
</div>
</div>
but it prints the label not the icon
What should I do to show my icons?
Upvotes: 0
Views: 660
Reputation: 5358
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.
Upvotes: 0
Reputation: 42
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.
Upvotes: 1