Forums / Cotonti / Support / cache problems?

tensh
#1 2012-10-19 13:39

Hi;

I want to include a tpl based on location and lang.


This code works:

<!-- IF {PHP.env.ext} == "contact" AND {PHP.lang} == 'pl' -->	

		{FILE "{PHP.cfg.themes_dir}/{PHP.theme}/inc/pl-{PHP.env.ext}.tpl"}

<!-- ENDIF -->

but this one doesn't work:

<!-- IF {PHP.env.ext} == "contact" -->	

		{FILE "{PHP.cfg.themes_dir}/{PHP.theme}/inc/{PHP.lang}-{PHP.env.ext}.tpl"}

<!-- ENDIF -->

Why? The second one would be easier, now I have to repeat the same code for all 3 languages

GHengeveld
#2 2012-10-19 15:03

A wild guess, but perhaps you can try {PHP.usr.lang} instead of {PHP.lang}.

Also, you may want try outputting the filepath and see what it is before attempting to include it. This could give some insight.

Trustmaster
#3 2012-10-19 18:02

General advice: don't use dynamically calculated variables in tpl FILE statements. FILE statements are static, they are compiled once a template is updated and afterwards the cached template behaves like there is no FILE statement at all but rather the entire file contents stands in its place.

May the Source be with you!
tensh
#4 2012-10-20 07:49

The output filepath was OK, but the template was cached to the last one used regardless of the language used.

So how should I include template based on language and location? Do I really have to write a plugin for it?

GHengeveld
#5 2012-10-20 08:31

It's probably easiest to use a single template for all languages, and use IF blocks within that template to show stuff for each language.

<!-- IF {PHP.lang} == 'pl' -->
Polish stuff
<!-- ENDIF -->
<!-- IF {PHP.lang} == 'en' -->
English stuff
<!-- ENDIF -->
tensh
#6 2012-10-20 09:41

Yeah, at first it was like that, but the template was very big and I think it will not be easy to maintain :/ (3 languages, 6 sections, each has different slideshow in different languages)
I guess I'll have to write a plugin.

Trustmaster
#7 2012-10-20 11:41
<!-- IF {PHP.lang} == 'pl' -->
{FILE "{PHP.cfg.themes_dir}/{PHP.theme}/inc/pl-{PHP.env.ext}.tpl"}
<!-- ENDIF -->
<!-- IF {PHP.lang} == 'en' -->
{FILE "{PHP.cfg.themes_dir}/{PHP.theme}/inc/en-{PHP.env.ext}.tpl"}
<!-- ENDIF -->

 

May the Source be with you!
tensh
#8 2012-10-20 19:22

But sometimes I use {PHP.env.ext} and sometimes {PHP.c} so it's not that easy.

Thank you for help anyway. :)

Trustmaster
#9 2012-10-21 06:31

For {PHP.c} differentiation use different templates instead: page.CAT.tpl and page.list.CAT.tpl.

May the Source be with you!
tensh
#10 2012-10-22 11:22

Yes I know, but it's all in header, and I want to avoid custom headers, I have an impression that site runs slower if custom headers are enabled.
I just made a lot of IFs, it looks so-so.

Thanks for help :)