首页 > 解决方案 > Pass html element value to laravel Blade IF

问题描述

i need help how to pass &{currentQuestion.id_soal} to laravel if, example:

@if($s->id == &{currentQuestion.id_soal} )

this is the script:

 output.push(
        `<div class="slide">
            @foreach ($soal as $key => $s) 
            @php
              $ids = ${currentQuestion.id_soal}
              @if($s->id ==  $ids  )
                <p>{!!$s->soal!!}</p>
              @endif
            @endphp
            @endforeach

           <img src="{{ asset('/soal_gambar${currentQuestion.gambar}')}}" style="max-width: 100%;" onerror="this.style.display='none'"/>
           <div class="answers"> ${answers.join("")} </div>
         </div>`
      );

标签: javascriptlaravel-5

解决方案


使用这个{!! $data !!},它显示内容而不转义 HTML 特殊字符。

来源:https ://laravel.com/docs/5.8/blade#displaying-data


推荐阅读