Laravel 4-渲染递归@include


Laravel 4 - Render recursive @include

我想获得带有递归@include标记的模板的渲染字符串。不幸的是,render()方法似乎不支持递归性:

return View::make('bind', $data)->render();

这是我的观点:

{{$namespace}}'Decorators'{{$decorators[$i++]}}
<?php $tab = str_repeat("'t", $i) ?>
{{$tab}}(
    {{$tab}}new @if(count($decorators) < $i)@include('bind')@endif
{{$tab}})

这就是我应该得到的:

Workflows'Decorators'Foo
(
    new Workflows'Decorators'Bar
    (
        new 
    )
)

这就是我得到的:

Workflows'Decorators'Foo
(
    new @include('bind')
)

尽管如此,如果我显示视图而不是渲染它,我可以看到正确的源代码。

有没有递归渲染视图的方法?

Laravel要求@指令出现在单独的行中。换句话说,每行只有一个标志。在某些情况下,Laravel会给你一个编译错误:在其他情况下,你只会得到神秘的结果(就像你的情况一样)。

因此,按照以下方式重写您的代码,它应该可以工作:

@if (count($decorators) < $i)
    @include('bind')
@endif