Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use arbitrary file extensions for views, and include full filename in view specification #301

Open
dubaaron opened this issue Jan 11, 2017 · 2 comments

Comments

@dubaaron
Copy link

Hello,

I have a whole bunch of twig files with a ".html" extensions (i.e., "structure.html").

These files are in a directory hierarchy, and many include or extend others.

These were built prior to my adopting Laravel, and so all the calls to include or extends specify the full filename and directory (relative to the template base directory).

Example: {{ extends 'main_themes/structure.html' }} etc., etc.

I would like to ditch all the fancy laravel magic of specifying view names without file extensions, and just be able to specify full file names with extensions, so all the templates don't have to be reworked. (These template files are in a library that is also shared by code that isn't coming out of laravel, and thus needs to specify full filenames; I'd like to continue to share the code this way).

I can get around this by loading the Twig environment myself directly,, but then I don't get the benefit of all the extensions and Laravel functions that TwigBridge automatically includes, as well as its automatic injection of certain data into the views.

Is there any way to achieve this?

I'm aware of using
View::addExtension('html', 'twig');
which lets me use both .html and .twig files and load them with laravel view functions and inside the templates (without the extension), but this still doesn't let me just leave the full filenames in there.

I also tried
'View::addExtension('', 'twig'); (adding an empty string as extension), but that didn't seem to work, nor did escaping the dots with backslashes (return view('main_themes/theme.html');`, etc.).

(N.B. I have found that using a '/' as directory separator instead of a dot ('.') does work; which is nice, and useful, but still doesn't solve the problem.)

@OPM87
Copy link

OPM87 commented Jan 16, 2018

Hey,
did you find a solution by now?
Looks the root of this problem is in https://github.com/laravel/framework/blob/5.5/src/Illuminate/View/FileViewFinder.php#L127

Maybe to solve this the ViewServiceProvider and FileViewFinder must be replaced.

#159 , #323

@dubaaron
Copy link
Author

dubaaron commented Jan 16, 2018

I'm pretty sure I just did a workaround, bypassed using the TwigBridge and just called Twig views manually, using the Twig class directly (e.g., Twig->render(...)) ... doesn't give me the Laravel magic (vars and such) in the views, but I can pass what I need into the view manually, just like I'm used to doing when using Twig in non-Laravel contexts.

Thanks for your input, though; haven't dug deeper in quite a while.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants