thephpleague / plates

Native PHP template system
https://platesphp.com
MIT License
1.47k stars 180 forks source link

out of default dir allocation in Template::render (feature or bug?) #7

Closed mindyk closed 10 years ago

mindyk commented 10 years ago

my default template dir is

new \League\Plates\Engine('path/to/templates');

and my template structure looks like

`-- path
    `-- to
        `-- templates
            |-- index.php
            |-- login
            |   |-- index.php
            |   `-- partial.form.php
            `-- registration
                `-- index.php

as i cant imagine that using the "addFolder()" function is intented here i am doing this in my ctrl

$view->render('login/index')
// or
$view->render('registration/index')
$view->render('registration/success')

but the possibility to reach for nested folders like this is not documented. So am i using it as intented or should the render function restrict me from reaching deeper into the path

thx for your hard work

reinink commented 10 years ago

but the possibility to reach for nested folders like this is not documented.

You're right, it's sort of assumed. What you're doing here is totally fine.

You can use folders if you want to "namespace" your templates. Here is something that I posted on Reddit yesterday about namespaces:

More importantly, what I was going for with the namespaces is actually the ability to decouple the filesystem from the templates as much as possible. Using syntax like emails::welcome allows you to define your email directory once (ie. in your bootstrap), making it really easy to change later if necessary. Hard coding folders means you have to update every template reference.

So, if you wanted, you could add a namespace for your registration views, like this:

$plates->addFolder('registration', 'path/to/templates/registration');

The, you could render it like this:

$template->render('registration::index');

Using nested folders or namespaces are both acceptable approaches and both will work. It's really comes down to how you prefer to organize your application. Myself, I tend to only namespace different sections of my applications. For example, here are some common namespaces I use:

Hope that helps.

mindyk commented 10 years ago

Thx for the answer.