Laravel 4 - Render recursive @include

I would like to get the rendered template string with recursive @include tags. Unfortunately, the method render()

does not seem to support recursion:

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

      

It's my opinion:

{{$namespace}}\Decorators\{{$decorators[$i++]}}
<?php $tab = str_repeat("\t", $i) ?>

{{$tab}}(
    {{$tab}}new @if(count($decorators) < $i)@include('bind')@endif

{{$tab}})

      


This is what I should get:

Workflows\Decorators\Foo
(
    new Workflows\Decorators\Bar
    (
        new 
    )
)

      

This is what I get:

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

      

However, if I render the view instead of rendering it, I can see the correct source code.

Is there a way to recursively render views?

+3


source to share


1 answer


Laravel requires directives to @

appear on separate lines. They say otherwise, only one character per line. In some cases, Laravel gives you a compilation error: in others, you only get mysterious results (just like your case).

So, rewrite your code like below and it should work:



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

      

+2


source







All Articles