0

I know that {{ }} is laravel 4 operator but what if i use this in laravel 5.

I am trying it in laravel5 , it works but show some weird output

so should i use this operator or not in laravel 5???

2
  • Are you talking about Blade output? Commented Oct 9, 2015 at 8:01
  • Refer laravel.com/docs/5.1/blade and if the issue still exists share the code and present a desired output image or something like that Commented Oct 9, 2015 at 8:08

2 Answers 2

1

The blade syntax in Laravel 4.x was as follows

  • {{ $variable }} to output a variable without escaping the contents.
  • {{{ $variable }}} to output a variable whilst escaping the contents.

In Laravel 5.x this was changed to

  • {!! $variable !!} to output a variable without escaping the contents.
  • {{ $variable }} to output a variable whilst escaping the contents.

The reason you're seeing "weird" output is because the content which previously wasn't being escaped now is. What you're seeing is HTML entities and such being converted.

In order to get the expected output you'll need to change your blade templates to use {!! $variable !!} where appropriate.

If you don't want to go through all of the blade templates to make the change you can do the following

Add the following lines at the bottom of AppServiceProvider@register:

\Blade::setRawTags('{{', '}}');
\Blade::setContentTags('{{{', '}}}');
\Blade::setEscapedContentTags('{{{', '}}}');

This should not be done lightly, and may make your application more vulnerable to XSS exploits. Also, comments with {{-- will no longer work.

These changes are documented in the Upgrade guide under the heading Blade Tag Changes.

Sign up to request clarification or add additional context in comments.

Comments

1

The brackets are from blade, a template engine included in laravel 4 and 5.

It helps you to write easy code by converting a <your name>.blade.php into a full php file.

Hello, {{ $name }}.

will be converted to

Hello, <?php echo $name ?>

Remember the brackets will use htmlspecialchars so when you want to print a html element you need

{!! $myElement !!}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.