The Slim Framework support forum has moved to This Tender forum is no longer maintained or monitored.

Multiple templates directories using Slim's render function

Kapoler's Avatar


03 Jul, 2015 08:10 AM


I'm not using Twig at the moment but Slim's built-in function render.

To render a template, I do

$app->render('myfile.php', array('myvar' => $myvar,));

I set up my view directory afterward:

$app->config('templates.path', get_path_view());

where get_path_view() is:

function get_path_view($user)
{ if (is_dir('style/'.$user['style'].'/view')) { return APP_ROOT.'style/'.$user['style'].'/view'; } else { return APP_ROOT.'view'; } }

I use /view directory as default is /style/mystyle/view does not exist (custom template).

However, I don't want to setup a full directory if I only have a few changes compared to the default directory.

I usually have multiple renders in one file, so I'd like to load my view file from the /style/mystyle directory if it exists, and /view otherwise, for each file.

I have not found how to do this yet. Is there a way to customize render function, or to get an array of loaded templates before $app->run(); ?

Thank you!

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac