I'd like to get the rendered string of a template with recursive @include tags. Unfortunately it seems that the render() method doesn't support recursivity:
return View::make('bind', $data)->render();
This is my view:
{{$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')
)
Nevertheless if I display the view instead of rendering it, I can see the correct source code.
Is there a way to render views recursively?
Laravel requires that @ directives appear on separate lines. Said another way, only one at sign per line. In some cases, Laravel gives you a compile error: in others, you just get mysterious results (as was your case).
So, rewrite your code as below and it should work:
@if (count($decorators) < $i)
@include('bind')
@endif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With