Jump to content
adrianmak

should all template files put under site/templates folder ?

Recommended Posts

Yes, as far as I know.

Maybe there is some way to overrule that, but the mainstream way is to put them in tempates site/templates folder.

Share this post


Link to post
Share on other sites

Basicly you have one folder for templates by default. This is configured to be in "site root" + templates/

You are able to overrule this setting from the site/config.php as follow

$config->urls->templates = $config->urls->site . 'mytemplates/';
$config->paths->templates = $config->paths->site . 'mytemplates/';

A trick i use a lot when developing in a live site is to duplicate the template folder and rename the copy to templates-dev. Then make sure i have an other domain (or subdomain) pointing to the hosting, for example dev.domain.ext and for the live site on www.domain.ext

With the following code i can access the development templates while normal visitors keep getting the default templates.

/**
* Development: Alias for template-dev access
*
*/
if($_SERVER['HTTP_HOST'] == 'dev.domain.ext') {
    $config->urls->templates = $config->urls->site . 'templates-dev/';
    $config->paths->templates = $config->paths->site . 'templates-dev/';
    $config->debug = true;
}

You can make up all kind of 'rules' to go by when overruling the templates folder with php from the config.php file.

For example serving the same site with different layout and code for mobile on m.domain.ext

/**
* Mobile: Alias for template-mobile access
*
*/
if($_SERVER['HTTP_HOST'] == 'm.domain.ext') {
    $config->urls->templates = $config->urls->site . 'templates-mobile/';
    $config->paths->templates = $config->paths->site . 'templates-mobile/';
}
  • Like 24

Share this post


Link to post
Share on other sites

I think maybe the original question was not about changing the path to the folder where templates reside, but rather about being able to put template files in different subfolders of site/templates (or something different, adjusted with the methods, described above).

Although you can change the file used as template file for the template in Admin -> Setup -> Templates -> Edit Template on the Files tab, you cannot point to something like "views/product/product.php" there as far as I know (at least it did not work when I tried). You can only choose different file in template folder. It could be just great if you could.

  • Like 2

Share this post


Link to post
Share on other sites
On 1/15/2015 at 5:38 PM, Ivan Gretsky said:

you cannot point to something like "views/product/product.php" there as far as I know

Just want to add for anyone reading this post, that while in the admin this cannot be done, it is doable via code. By putting something like this into init.php,:

$templates->get('home')->filename = $config->paths->templates . 'views/home/home.php';

it is possible to store a template file wherever you want.

Read more about this in this topic: https://processwire.com/talk/topic/2676-configuring-template-path/

 

  • Like 2

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...