Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Add support for multiple templates dirs #29

Open
raxell opened this issue Jun 27, 2014 · 5 comments
Open

Add support for multiple templates dirs #29

raxell opened this issue Jun 27, 2014 · 5 comments

Comments

@raxell
Copy link

raxell commented Jun 27, 2014

Can you add support for setting multiple templares dirs? Twig already support it, why don't add it to this lib?

Simply edit in Slim\Views\Twig:

/**
 * DEPRECATION WARNING! This method will be removed in the next major point release
 *
 * Get a list of template directories
 *
 * Returns an array of templates defined by self::$twigTemplateDirs, falls
 * back to Slim\View's built-in getTemplatesDirectory method.
 *
 * @return array
 **/
private function getTemplateDirs()
{
    if (empty($this->twigTemplateDirs)) {
        return $this->getTemplatesDirectory();
    }
    return $this->twigTemplateDirs;
}

/**
 * Sets an array of paths where to look for templates.
 * @param  string|array $directory
 */
public function setTemplatesDirectory($directory)
{
    $this->templatesDirectory = $directory;
}
@tassoevan
Copy link
Contributor

why don't add it to this lib?

Maybe for conformance with Slim setting templates.path?

@ikhsan017
Copy link

Currently, I am modifying it on the fly

        $twigInstance   = $app->view->getEnvironment();
        $twigLoader     = new Twig_Loader_Filesystem();

        foreach ($templatePaths as $path) {
                $twigLoader->addPath($path);
        }

        $twigLoader->addPath($app->config('templates.path'));


        $twigInstance->setLoader($twigLoader);

@raxell
Copy link
Author

raxell commented Jun 27, 2014

Maybe for conformance with Slim setting templates.path?

templates.path should refers to the template engine you are using, not to the Slim default setting. If Twig gives the option to choose more dirs for templates, why shouldn't I be able to use this option in Slim for the Twig engine?

@ikhsan017 I know that I can change the loader, but why use this "trick" when the configuration can be setted in the Slim constructor? This modify only affect Twig, for other template engine you can continue to use a string.

@tassoevan
Copy link
Contributor

templates.path

The relative or absolute path to the filesystem directory that contains your Slim application’s template files. This path is referenced by the Slim application’s View to fetch and render templates.

To change this setting after instantiation you need to access Slim’s view directly and use its setTemplatesDirectory() method.

Source: http://docs.slimframework.com/#Application-Settings

@silentworks
Copy link
Member

I fully agree with you @raxell we will be revisiting this for Slim 3 as View will manage their own config at that point. What would you suggest for the current Slim 2.4.* builds?

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

No branches or pull requests

4 participants