rcrowe / TwigBridge

Give the power of Twig to Laravel
MIT License
895 stars 168 forks source link

How do I include a blade template from a twig one? #226

Open tremby opened 8 years ago

tremby commented 8 years ago

I saw that this was asked in #39 and was then referenced as part of "Improve template loading" in 0.6.0 (#62 and #72) and checked off, but it's not clear how exactly it was improved.

The suggested workaround of {{ view_make('view-name') }} is not working for me. I'm trying to include a partial provided by a package so I'm doing {{ view_make('package-name::template-name') }}. I'm told view_make doesn't exist.

Attempting to include the template directly (with Twig's include statement) doesn't work either.

barryvdh commented 8 years ago

Why would you want this?

tremby commented 8 years ago

I am using a package which provides various partials in Blade format, like widgets. I don't want to rewrite this package with Twig templates, because then I wouldn't benefit from upstream fixes.

tremby commented 8 years ago

It would also be useful if I were to transition an existing application from Blade to Twig (as I have been considering doing). It's not practical with applications of a certain scale to do it all at once: this would allow me to do it piece by piece.

barryvdh commented 8 years ago

What about adding the 'View' facade to your config, and call View.make('view-name'), or add view to the functions in the config: {{ view('view-name') }}

tremby commented 8 years ago

That seems reasonable, at least for now.

In theory would it be possible to overload Twig's include statement to run Laravel's view behind the scenes? It would be nice if this were transparent, i.e. the include was format-agnostic.

barryvdh commented 8 years ago

I don't think you can really mix them, except for just rendering something as a string.

tremby commented 8 years ago

In this particular case that would suffice. But in other cases (transitioning an app bit by bit) it would not.

That's a shame to hear.

You can consider this ticket a wishlist item, then. Thanks.

shehi commented 8 years ago

These issues really need closing.