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

More methods to interface #2

Open
weierophinney opened this issue Dec 31, 2019 · 2 comments
Open

More methods to interface #2

weierophinney opened this issue Dec 31, 2019 · 2 comments

Comments

@weierophinney
Copy link
Contributor

Hi,

Expressive currently have an addPath signature as below.

    /**
     * Add a template path to the engine.
     *
     * Adds a template path, with optional namespace the templates in that path
     * provide.
     *
     * @param string $path
     * @param string $namespace
     */
    public function addPath($path, $namespace = null);

But recently I was experimenting and noticed it may be good to have a prependPath also. Basically the idea is I can change the path of the file located to load it first .

I noticed there is a prependPath in twig .

Can we add a prependPath to this interface for the next higher version ? This helps to work with appending path.

Bonus :

If anyone thinks setPaths is nice to have. Please do add .

Thank you.


Originally posted by @harikt at zendframework/zend-expressive-template#12

@weierophinney
Copy link
Contributor Author

I'm not really sure I understand the use case. Right now you can setup the paths relatively to the project root and / or modules. This is done for you if you've setup your project with the skeleton.

So if you store your templates somewhere else you can set it in your config. Or if you have your templates temporary stored somewhere else you could setup the template paths in templates.local.php.

Also since TwigRenderer 1.2.0 you can have access to the Twig_Environment directly. From there you can use the getLoader() function and use prependPath(), setPaths() and all other public functions available in Twig_Loader_Filesystem.


Originally posted by @geerteltink at zendframework/zend-expressive-template#12 (comment)

@weierophinney
Copy link
Contributor Author

Hi @xtreamwayz ,

Thank you for looking into this. I am not looking for just one implementation. I am looking for every renderer, whether it is twig, mustache, plate or you name it.

Why ?

Say I have module X .

X
    - src
    - Module.php
    - templates

The Module.php contains something like

$template = $di->get('Zend\Expressive\Template\TemplateRendererInterface');
$template->addPath(__DIR__ . DIRECTORY_SEPARATOR . 'templates', 'example');

In the action I have the namespace to render the file.

// WelcomeAction.php
    $this->template->render('example::welcome', $data)

What I am looking with a prependPath is I can tell $template = $di->get('Zend\Expressive\Template\TemplateRendererInterface'); to add the path to the earlier added path.

You could argue that I can add the ApplicationModule.php to load first. But this is the case what I am looking for.

Hope you understand what I am looking for.

Thank you.


Originally posted by @harikt at zendframework/zend-expressive-template#12 (comment)

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

1 participant