user13523236
user13523236

Reputation: 135

print icon obtained from db - laravel

I want to put together a menu and get an icon dynamically.

the result i want is something like this: enter image description here

Database table:

enter image description here

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

enter image description here

What should I do to show my icons?

Upvotes: 0

Views: 660

Answers (2)

Dan
Dan

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

Stefan Br&#228;u
Stefan Br&#228;u

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

Related Questions