在Blade指令中使用Blade指令 [英] Using a Blade directive in a Blade directive

查看:109
本文介绍了在Blade指令中使用Blade指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Laravel 5.1.我试图在我的自定义Blade指令中使用Blade指令(@extend).

I'm using Laravel 5.1. I am trying to use a Blade directive (@extend) with my custom Blade directive.

Blade::directive('base', function() use ($theme) {
  return "@extends($theme)"
});

但是,上面的代码仅按字面显示内容(@extends($theme))

However, the above code only literally displays the contents (@extends($theme))

推荐答案

与我之前的评论相反,我认为使用刀片编译器可以(但未经测试).

Contrary to a comment I made earlier, I think this is possible (but untested) using the blade compiler.

Blade::directive('base', function() use ($theme) {
    return Blade::compileString("@extends({$theme})");
});

这篇关于在Blade指令中使用Blade指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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