Laravel 5: Display HTML with Blade

后端 未结 20 2183
栀梦
栀梦 2020-11-22 16:21

I have a string returned to one of my views, like this:

$text = \'

Lorem ipsum dolor

相关标签:
20条回答
  • 2020-11-22 16:33

    For laravel 5

    {!!html_entity_decode($text)!!}
    

    Figured out through this link, see RachidLaasri answer

    0 讨论(0)
  • 2020-11-22 16:33

    You can do that using three ways first use if condition like below

    {!! $text !!}
    

    The is Second way

    <td class="nowrap">
    @if( $order->status == '0' )
        <button class="btn btn-danger">Inactive</button>
    @else
        <button class="btn btn-success">Active</button>
    @endif
    </td>
    

    The third and proper way for use ternary operator on blade

    <td class="nowrap">
          {!! $order->status=='0' ? 
              '<button class="btn btn-danger">Inactive</button> : 
              '<button class="btn btn-success">Active</button> !!}
    </td>
    

    I hope the third way is perfect for used ternary operator on blade.

    0 讨论(0)
  • 2020-11-22 16:35

    For who using tinymce and markup within textarea:

    {{ htmlspecialchars($text) }}
    
    0 讨论(0)
  • 2020-11-22 16:36

    You need to use

    {!! $text !!}
    

    The string will auto escape when using {{ $text }}.

    0 讨论(0)
  • 2020-11-22 16:36

    You can use {!! $text !!} for render HTML code in Laravel

    {!! $text !!}
    

    If you use

    {{ $text }}
    

    It will not render HTML code and print as a string.

    0 讨论(0)
  • 2020-11-22 16:36

    If you want to escape the data use

    {{ $html }}
    

    If don't want to escape the data use

    {!! $html !!}
    

    But till Laravel-4 you can use

    {{ HTML::link('/auth/logout', 'Sign Out', array('class' => 'btn btn-default btn-flat')) }}
    

    When comes to Laravel-5

    {!! HTML::link('/auth/logout', 'Sign Out', array('class' => 'btn btn-default btn-flat')) !!} 
    

    You can also do this with the PHP function

    {{ html_entity_decode($data) }}
    

    go through the PHP document for the parameters of this function

    html_entity_decode - php.net

    0 讨论(0)
提交回复
热议问题