Home > other >  (Laravel) I save blade template with variable in database, how to render the variable?
(Laravel) I save blade template with variable in database, how to render the variable?

Time:01-15

I save plain HTML with variable in database, like this

<div>
        <span>Nomor: <strong>{{ $pen->nomor_sertifikat ?? "" }}</strong></span>
        <span>
            Nilai: <strong>Rp{{ number_format($pen->nilai_pen,0,',','.')}} 
            </strong>
        </span>
</div>

When I call data from database in laravel blade, {!! $data->content !!}, the result is like this

Nomor: {{ $pen->nomor_sertifikat }} Nilai: Rp{{ number_format($pen->nilai_pen,0,',','.')}}

the data inside {{ }} can't render. How to solve it? thanks

CodePudding user response:

use

 <?= (which you want to input ) ?> 

or

<?php echo  (which you want to input ) ?>

but you need to be careful with xss. you can use htmlpurifier

CodePudding user response:

When calling it in a blade template you should put it into {!! !!} tags

  •  Tags:  
  • Related