我如何在laravel刀片宏中使用包含? [英] How do I use includes in a laravel blade macro?

查看:84
本文介绍了我如何在laravel刀片宏中使用包含?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Laravel 4中的站点设计一个后端.它将具有许多数据输入表单,其中一些将分解为选项卡式页面.

I am designing a back end for a site in Laravel 4. It will have a number of data entry forms, some of which will be broken up into tabbed pages.

对于单个视图,它看起来像这样:

For an individual view it looks like this:

<ul>
<li id='menu0' class='menu active'>Main</li>
<li id='menu1' class='menu'>Secondary</li>
<li id='menu2' class='menu'>Advanced</li>
</ul>

<div id='tab0' class='tab active'>
@include('_mainfields')
</div>

<div id='tab1' class='tab'>
@include('_secondfields')
</div>

<div id='tab2' class='tab'>
@include('_advancedfields')
</div>

理想情况下,我想将其转换为宏:

Ideally, I want to convert this to a macro:

Form::tabify(['Main','Secondary','Advanced'],'_mainfields','_secondfields','_advancedfields'])

典型的@include文件将包含如下刀片代码:

A typical @include file would contain blade code like this:

<div class='formfield'>
{{ Form::label('dress_description','Description') }}
{{ Form::input('text','dress_description') }}
</div>

编写宏以生成UL部分是微不足道的.但是,涉及到包含内容时,我碰壁了.我看不到如何将其提取到宏中.宏本身不能包含@include,正如用PHP编写的那样. php include无效,因为include中的刀片代码无法得到处理.

Writing a macro to generate the UL portion is trivial. However, I hit a wall when it comes to the includes. I can't see how I can extract that out to the macro. The macro itself can't contain an @include, as its written in PHP. A php include wouldn't work, as the blade code in the include wouldn't get processed.

那么还有另一种方法吗?

So is there another way?

推荐答案

您可以直接渲染它们:

View::make('your-included-template');

这篇关于我如何在laravel刀片宏中使用包含?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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