fuel / parser

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

Fixed searched paths for modules with Twig and removed paths duplicated #51

Closed billmn closed 11 years ago

billmn commented 12 years ago

I'm not sure if this is the best method to fix the problem.

I will try to explain the problem using an example :

// REQUEST : Open admin/auth/login.html

// FOLDERS
// ---------------------------------------------------------
app/
    ...
    modules/
        module1/
            views/
                admin/
                    auth/
                        login.twig
                        forgot.twig
                    base.twig
                ...
// ---------------------------------------------------------

// auth/login.twig (VIEW NOT FOUND)
// ---------------------------------------------------------
{% extends 'admin/base.twig' %}

{% block contents %}
Login page
{% endblock %}
// ---------------------------------------------------------

// BEFORE : Searched paths (Parser/classes/view/twig.php line 45)
/app/modules/module1/views/admin/auth,
/app/views

// FIX : Add main Module's Views paths to searched paths

// AFTER : Searched paths
 /app/modules/module1/views/admin/auth
 /app/modules/module1/views
 /app/views

Suggestions?

WanWizard commented 12 years ago

I'm not sure either. ;)

It will solve your particular use case, but it's a hack as it solves only that. Any other location will still fail.

To solve this properly you need a way to (dynamically) tell twig what your search paths are.

billmn commented 12 years ago

I think that is a problem for every dev that use Twig templates in a subfolder (in modules) ... is not a my particular case :)

"Any other location will still fail. " Why? I've only added the module views path ... anything else

"To solve this properly you need a way to (dynamically) tell twig what your search paths are." Mmmm what do you mean? This add the search paths to Twig ... no?

foreach ($this->active_request->get_paths() as $path)
{
      array_unshift($views_paths, $path.'views');
}

Thank you man for the support! :)

WanWizard commented 12 years ago

That's my point.

Your views (the one you extend) are there, and therefor this solves your problem. Another user might have another standard folder layout in which their base views are elsewhere, and for them this is not a solution.

billmn commented 12 years ago

Paste IRC converstation :

[17:22] <billmn> "which their base views are elsewhere, and for them this is not a solution"
[17:23] <billmn> ... mmm but this will still work as before right?
[17:23] <WanWizard|busy> yes, as in "it will still not work for them"
[17:29] <billmn> mmm ... for consistency ... what do you think about using the same syntax for normal views? like \View::forge('othermodule::subdir/view');
[17:29] <billmn> this method add the main path of the module to search paths?
[17:45] <WanWizard|busy> it's the twig 'extend' that I'm talking about. if you use twig's own logic to access files, you will have to tell twig where to find them.
[17:46] <WanWizard|busy> your fix does that, but hardcoded for the location that works for you.
[17:47] <WanWizard|busy> for other people using different locations, that is not a solution. to fix this you need a way for me to set my "twig search paths", and you set yours, so that it works for both of us
WanWizard commented 11 years ago

Looking back at this, shouldn't this solve it (I'm not a twig user):

{% extends '../base.twig' %}