更改Laravel刀片定界符 [英] Changing Laravel Blade Delimiter

查看:125
本文介绍了更改Laravel刀片定界符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道您可以使用更改默认刀片分隔符

Blade::setEscapedContentTags('[[', ']]');
Blade::setContentTags('[[[', ']]]');

但是我不知道应该把它放在哪里,这样它只会影响单个刀片模板,而不是将它放在app/start/global.php会影响整个应用程序.

解决方案

如果您只想对单个视图使用不同的标签,则可以在将生成视图的闭包或控制器操作中设置标签.

Route::get('/', function()
{
    Blade::setEscapedContentTags('[[', ']]');
    Blade::setContentTags('[[[', ']]]');

    return View::make('home');
});

如果您想在应用程序布局中使用普通标签{{}},但在嵌套视图中使用自定义标签,则可能会遇到问题-我不确定最好的方法是什么. /p>

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.

解决方案

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.

这篇关于更改Laravel刀片定界符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆