I know that you can change the default blade delimiter using
Blade::setEscapedContentTags('[[', ']]');
Blade::setContentTags('[[[', ']]]');
However I don't know where should I put it so that it only affect single blade template as opposed to putting it at app/start/global.php
which affect whole application.
How to Create Custom Blade Directive in Laravel? 1 Step 1: Create Custom Blade Directive 2 Step 2: Create Route 3 Step 3: Create Blade File 4 Step 4: Run Development Server More ...
Blade is the simple, yet powerful templating engine that is included with Laravel. Unlike some PHP templating engines, Blade does not restrict you from using plain PHP code in your templates.
Layouts are often the starting point of many web development projects. Laravel Blade template engine enables the developer to produce HTML based sleek designs and themes. All views in Laravel are usually built in the blade template.
By default, Blade (and the Laravel ehelper) will double encode HTML entities. If you would like to disable double encoding, call the Blade::withoutDoubleEncodingmethod from the bootmethod of your AppServiceProvider:
If you only want to use different tags for a single view, you can set the tags in the closure or controller action that will generate the view.
Route::get('/', function()
{
Blade::setEscapedContentTags('[[', ']]');
Blade::setContentTags('[[[', ']]]');
return View::make('home');
});
This could be an issue if you want to use the normal tags {{
and }}
in an application layout but your custom ones in a nested view - I'm not sure what the best approach there would be.
The solution with Blade::setEscapedContentTags
/ Blade::setContentTags
doesn't work in the latest versions of Laravel (checked at 5.6).
The recommended approach is (https://laravel.com/docs/5.6/blade#blade-and-javascript-frameworks):
Blade & JavaScript Frameworks
Since many JavaScript frameworks also use "curly" braces to indicate a given expression should be displayed in the browser, you may use the
@
symbol to inform the Blade rendering engine an expression should remain untouched. For example:
Hello, @{{ name }}.
In this example, the
@
symbol will be removed by Blade; however,{{ name }}
expression will remain untouched by the Blade engine, allowing it to instead be rendered by your JavaScript framework.The @verbatim Directive
If you are displaying JavaScript variables in a large portion of your template, you may wrap the HTML in the
@verbatim
directive so that you do not have to prefix each Blade echo statement with an@
symbol:@verbatim <div class="container"> Hello, {{ name }}. </div> @endverbatim
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With