Jump to content

How can i changed template path?


sebafurfaro
 Share

Recommended Posts

Hi!

I create a directory structure inside the main template directory.

So, the templates are inside a directory called pages.

/site/template/pages/template1.php
/site/template/pages/template2.php

But when I create a template from the admin, I get an error saying ProcessTemplate: No new template files were found in: /geointranet/site/templates/*.php. How can that core path be modified? It's possible?

Thanks to everyone!

Link to comment
Share on other sites

Thanks @3fingers

I tried to enter this condition

if($user->hasRole('superuser')) {
    $config->setLocation('templates','site/templates/pages/');
}
//or the same example
if($user->name =='username') {
    $config->setLocation('templates','site/templates/pages/');
}

in both _init.php and config.php, and it still doesn't work. I do not know what I'm doing wrong.

Link to comment
Share on other sites

3 hours ago, sebafurfaro said:

in both _init.php and config.php, and it still doesn't work

You can't do it in those files, use init.php instead, as opposed to _init.php. The latter is just a convention and often used like this:

/**
 * _init.php initializes variables output in _main.php
 *
 * This file is automatically prepended to all template files as a result of:
 * $config->prependTemplateFile = '_init.php'; in /site/config.php.
 *
 * Automatic inclusion for any given template can be disabled:
 * in admin: Setup > Templates > [some-template] -> "Files" tab -> "Disable automatic prepend file".
 */

In config.php the user is not yet known, as it runs before PW populates the $user and other API variables. 

Link to comment
Share on other sites

I moved the snippet to the init.php file and I get this error:

image.thumb.png.0b6aa4c4f770b092c850256a19e8fa98.png

I tried the same example from here 

https://processwire.com/blog/posts/pw-3.0.141/#new-hookable-templates-gt-filemodified-method

And I get the same error. So, I tried this one:

$config->setLocation('templates', 'site/templates/pages/');

& this one:

$config->setLocation('templates','site/pages/');

For the last one, I move the directory pages into site, but the error is the same.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...