0

I have a master.blade.php which contains @yield('page_tagline')

I want to use it like so @section('page_tagline', __('pages.home.tagline'))

This will work if the translation does not contain any html, but it does.

So how can i use it like that without blade escaping it ?

frogeyedman
  • 534
  • 1
  • 5
  • 23
  • Did either of the answers below answer your question or do you still need help with it? – Rwd May 18 '19 at 17:24
  • @RossWilson your answer did in someway, i did not use it though. Will still accept it as a answer since it's the way to go. – frogeyedman May 20 '19 at 09:50

2 Answers2

1

One way to get around this would be to use the HtmlString class:

@section('page_tagline', new \Illuminate\Support\HtmlString( __('pages.home.tagline')))

You could then take this one step further and create a macro for the Str class or a global helper function.


Macro Example

In you AppServiceProvider (or any service provider you want) add the following to the boot method:

Str::macro('html', function ($string) {
    return new HtmlString($string);
});

Don't forget to add the following use statements to the class:

use Illuminate\Support\HtmlString;
use Illuminate\Support\Str;

Then you @section would look something like:

@section('content', Str::html( __('pages.home.tagline')))
Rwd
  • 34,180
  • 6
  • 64
  • 78
0

You should use

@section('page_tagline')
    {!! __('pages.home.tagline') !!}
@endsection

This way you can put HTML inside the tagline

Leonardo Rossi
  • 2,922
  • 2
  • 20
  • 28