I’m moving our OJS installation from 2.4.2 to 2.4.6. and I think I may have found a very easy way to add multiple templates directories as asked here and here.
Seems to work well but I’m a bit concerned about unexpected issues.
My changes:
I've created a new folder called "override" and inside this one, another called "templates"
I've made two small changes to PKPTemplateManager.inc.php file:
So it's just one modified line of code and another one added to PKPTemplateManager.inc.php. Smarty seems to check first if file exists on "override > templates", then on "templates" and finally on "lib > pkp > templates". All compiled and cache templates share already defined directories, no changes there.
My questions are: Does this involve any security or unexpected issues? Could this be moved to a plugin that extends PKPTemplateManager?
I’ve been testing it and have not found anything wrong so far. It allows to have all changes separated from the core files, except this one.
Thanks & cheers,
Andy
PS:
@beghelli pointed me in another topic to his great template manager plugin ( http://lib-git.lib.sfu.ca/beghelli/customTemplateManager) but I’ve got 206 changed files so I thought this way (multiple directories) would be easier for me to maintain or adjust our modifications during upgrades.
I also know OJS 3.0a will be available on August and it completely changes templates management but this may be helpful for 2.4 installations (if there’s no issues…).
I think your approach should work well, though you might want to check what happens when filenames clash – e.g. whether recompiles are triggered as expected by template file modifications. I remember running into a few small issues there.
Regards,
Alec Smecher
Public Knowledge Project Team
Regarding what you said, I’ve been searching for a solution and it seems recompiles should be correctly triggered by template file modifications if there’s a compile_id assigned. And I think I’ve found the code I needed here: framework/Smarty.php at master · joestump/framework · GitHub
So, added to the changes mentioned before, I’ve changed the fetch function this way:
private function getCompileID($template, $compile_id)
{
if (strlen($compile_id)) {
return $compile_id;
}
$compile_id = $this->template_dir . $template;
return sha1($compile_id);
}
Don’t know if this solves anything at all, but everything seems to work well right now. I’m going to continue with the tests and I’ll let you know if I find any issue.