Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to escape blade tags in laravel

I'm working on a small CRM system where users need the option to send emails to other users and to load predefined templates. Currently the templates are stored in my views/emails/templates folder. Example: new_order.blade.php

Inside the template I have the following code syntax:

Visit us at: {{{ (isset($isTemplate) && $isTemplate) ? '{{ $offerUrl }}' : $offerUrl }}}

This kind of works but parses the string that need to be outputed exactly like that to real php code.

Visit us at: <?php echo $offerUrl ?>

Is there any solution to echo blade tags?

like image 371
Tudor Ravoiu Avatar asked Jun 18 '15 06:06

Tudor Ravoiu


People also ask

How do you escape Laravel blade?

Actually Laravel supports {{}} and {{{}}} to escape data.

What is @yield used for in Laravel?

In Laravel, @yield is principally used to define a section in a layout and is constantly used to get content from a child page unto a master page.

What is Blade syntax in Laravel?

The Blade is a powerful templating engine in a Laravel framework. The blade allows to use the templating engine easily, and it makes the syntax writing very simple. The blade templating engine provides its own structure such as conditional statements and loops.


2 Answers

You can use the @{{ to escape a blade syntax. So you could use

'@{{ $offerUrl }}'
like image 99
Malitta N Avatar answered Oct 07 '22 15:10

Malitta N


That @{{ $offerUrl }} syntax works only if both(open and close) curly bracket pairs exist. Otherwise if string contains any curly bracket I suggest to use plane old php syntax like

<?php echo '$offerUrl }}'?>

and you will have nothing weird to ecape.

like image 1
Edgars Praulins Avatar answered Oct 07 '22 15:10

Edgars Praulins