fuel / parser

Fuel PHP Framework - v1.x template parser package adapters
http://fuelphp.com
64 stars 45 forks source link

Generic view is preferred above module. #77

Closed AssetsInc closed 10 years ago

AssetsInc commented 10 years ago

I'm currently trying to get a basic web app working, seperating my admin into a module.

I'm using Twig and the Parser package to manage templating.

I have two view called base.twig in fuel/app/views/ and fuel/app/modules/admin/views.

When I want to extend the admin template (the one in /modules/admin...) (from a controller in the module) I keep getting the generic one (app/views).

I have read the docs regarding views and parser at least fifteen times, and couldn't come up with a solution. MY last resort (renaming the admin template to base2 and adjusting the extending view) resulted in this error.

Controller and extending template

Checked against 1.8/develop and verified it happening there too.

WanWizard commented 10 years ago

You need to tell Twig where to look for templates.

By default, the parser driver for Twig adds the current view path (./modules/admin/views/user in your example) and ./app/views. If your template is somewhere else, it will not be found.

You configure the paths in the parser config file, the key "View_Twig.views_paths".

If you need something custom or dynamic, all you can do is create a custom parser (View_Twigger or something), have it extend \Parser\View_Twig, give it a config (copy the View_Twig entry), and modify the code.

AssetsInc commented 10 years ago

Did some research (considering my as of yet hobbyist state), and came up with this.

Works, and I am satisfied.

Case closed. Thanks for the pointers :)

AssetsInc commented 10 years ago

Too quick for being efficient... renamed the admin view back to base, and it is still chosen for extending.

Quick and dirty fix is renameing the admin template to something else then the generic view, but for the sake of consistency across modules, it'd be nice to fix this somehow. I take it that first view found is loaded?

WanWizard commented 10 years ago

I assume so. I don't use Twig myself.

Currently the parser adds the current path (the path of the template being loaded) first, and app/views second. Which is consistent with the way modules in Fuel behave, which is that local files (i.e. in the module) have a higher priority than global files.

As far as I can see, the only way to change that is to alter the order in which the paths are passed to Twig_Filesystem.

AssetsInc commented 10 years ago

I've finally found a workaround (with a little help from StackOverflow).

What I'm doing is adding a namespace for each module in the twig parser class and with this the ability to reference module specific templates like this {% extends '@example/template.twig' %}.

I've created a pull request with the neccessary changes (which exactly weren't that big...). This needs no setup in the config file and works out of the box.