nejib1 / smarty-php

Automatically exported from code.google.com/p/smarty-php
1 stars 0 forks source link

template_c conflict for files of same name in different directories #194

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Seem to be having an issue with the compilation of template files having the 
same name but in different directories. I'm using the extends: resource type.

the compiled file from files with the same name

I have a folder structure something like this:

/core/templates/layout.tpl
/core/admin/templates/index.tpl
/app1/templates/index.tpl
/app1/sub_app/templates/index.tpl
/app2/templates/index.tpl

There's a "core" with multiple applications in other folders and 
subapplications can be under core and those applications. Each app/subapp has 
its own templates/ dir and they all extend on layout.tpl in the core dir. Each 
app/subapp sets the smarty templateDir to its own templates subfolder.

Templates are being compiled into:
/core/smarty/template_c/

My call to render a page is:
$this->display("extends:/core/templates/layout.tpl|{$page}.tpl"); 

When using force compile, it works as expected. Without, all those index.tpl 
files get compiled to the same filename in templates_c/ and it will render 
whichever one is already saved.

I've read that Smarty v3 that should also take into account the dir of the tpl 
when building its cache id, so this isn't the behaviour I'm expecting.

I'm running 3.1.17 and seeing the same issue on Windows and Linux.

Appreciate the help

Original issue reported on code.google.com by partingw...@gmail.com on 29 May 2014 at 10:44

GoogleCodeExporter commented 9 years ago
Read the 3.1.16 Release Notes.

If you use interitance with variable file names you must set
$smarty->inheritance_merge_compiled_includes = false;

Original comment by Uwe.Tews@googlemail.com on 31 May 2014 at 1:08

GoogleCodeExporter commented 9 years ago
Hi Uwe, thanks for the suggestion. This didn't resolve the problem, 
unfortunately.

It would still take whichever index.tpl is already compiled in the template_c/ 
folder instead of being aware of the path of the index.tpl file, which is 
different for each.

I think this arises since I'm using relative directories when setting the 
template dir - the smarty compile id doesn't take into account the full path of 
the template file, rather only the relative path (which is 
./templates/index.tpl for each of these different apps/subapps.

I've managed to work around this by only passing directories by their 
full/absolute path to set/addTemplateDir(), instead of a path relative to the 
currently running script.

Should the compile id for a template take into account its absolute path, 
instead of just its relative path?

Original comment by partingw...@gmail.com on 1 Jun 2014 at 2:42

GoogleCodeExporter commented 9 years ago
Just for my understanding:

You use templates relative to the runing script, but if smarty is mixing things 
up you do have an absolute template_c folder. Right?

Original comment by Uwe.Tews@googlemail.com on 2 Jun 2014 at 2:46

GoogleCodeExporter commented 9 years ago
Each script runs in its own working directory. e.g. /app1/index.php will run in 
with /app1/ as its cwd while /app1/subapp/index.php will run with /app1/subapp/ 
as its cwd. each of these dirs has a templates/ subfolder where the .tpl files 
for that app live.

And then there's one global templates_c/ folder where all tpls get compiled, in 
/core/smarty/templates_c

Original comment by partingw...@gmail.com on 2 Jun 2014 at 3:02

GoogleCodeExporter commented 9 years ago
The bugfix is now in the SVN trunk and will later be included in 3.1.19

Original comment by Uwe.Tews@googlemail.com on 2 Jun 2014 at 8:15