Forums / Cotonti / General / Question with caching

Eugene
#1 2012-06-01 20:44

Hope you, guys, may figure out this. I explain steps I've made:

In header i have a $shablonpath variable which is connected with current category code.

In page.tpl I insert additional sub-template through

{FILE "themes/tvbclassic/inc/{PHP.shablonpath}.tpl"}

That code works great - inserting additional info - depending on cat...

BUT as turn on template caching in config - It looks like it cached first sub-template (depending on cat where I addressed the first) - and put that cache everywhere - in all cats. Turning off the cache make things work immediately...

Trustmaster
#2 2012-06-01 21:13

It is essential to understand how {FILE} statement works in CoTemplate. In General, CoTemplate splits work into 2 stages:

  1. Compilation of the abstract template.
  2. Parsing with the real data.

1st stage is performed once and then the results are cached. 2nd stage is performed on each and every request.

The FILE statement works on stage 1 and it works literally as #include statement works in C: it just replaces the statement with the contents of the file.

So, if you use a variable in the FILE path that changes at run-time from one request to another, then it is not going to work right for you. This is the limitation of the template engine and it is not likely to be changed any time soon for the reason of performance.

May the Source be with you!
Eugene
#3 2012-06-02 05:27

So, do i have opportunity to replace FILE with another function ?
or it is better use many IF in template to let CoTemplate do work instead of PHP part (not generate variable at all)?

Trustmaster
#4 2012-06-02 08:01

It depends on how complex your $shablonpath logic is. Generally what you're trying to achieve is done by using per-category templates like page.$category.tpl.

May the Source be with you!
GHengeveld
#5 2012-06-02 10:14
The easiest solution is to use page.mycategory .tpl like Trustmaster suggests. If you need more flexibility the only option is to write a plugin which code adds a tpl tag with your custom content based on the category code. Either way you probably don't need the shablonpath variable.
Eugene
#6 2012-06-02 14:35
#34512 GHengeveld:
The easiest solution is to use page.mycategory .tpl like Trustmaster suggests. If you need more flexibility the only option is to write a plugin which code adds a tpl tag with your custom content based on the category code. Either way you probably don't need the shablonpath variable.

1) page.mycategory.tpl - already used on that site in abundance. What I was talking is logical subdivision of category without need for multiplying templates...

2) So, your suggestion about plug is better - i'll do that now.

thank you guys...