View previous topic :: View next topic |
Author |
Message |
Hept Smarty n00b
Joined: 31 Jan 2014 Posts: 4
|
Posted: Fri Jan 31, 2014 5:11 pm Post subject: {include} cache_id not accepting $var |
|
|
Hello. I found a bug/feature within the {include} function.
Consider the following code
Code: |
{include file="home.tpl" cache_id=$var}
|
It throws "Undefined Index" error.
But all the following works
Code: |
{include file="home.tpl"}
{include file="home.tpl" cache_id=$var|default:'mycache'}
{include file="home.tpl" someVar=$var}
{include file="home.tpl" cache_id='foo'}
|
Is it a bug or a feature ?
My Smarty version is v3.1.16
Thanks!
Edit:
On
Code: | {include file="home.tpl" cache_id=$var|default:'mycache'} |
The cache_id value will always be mycache... |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sat Feb 01, 2014 11:44 am Post subject: |
|
|
I can't reproduce the problem.
Something seems not to be okay with the variable $var. what value does it have?
What do you get on {$var} and {$var|default:'mycache'} ? |
|
Back to top |
|
Hept Smarty n00b
Joined: 31 Jan 2014 Posts: 4
|
Posted: Wed Feb 05, 2014 1:03 pm Post subject: |
|
|
Actual code:
index.php
Code: | $smarty->assign('navbarCache','template|navbar|'.$category);
$smarty->display('category/show.tpl',$cachelink); |
template/bodyUpper.tpl
Code: | <nav role="navigation">
{include file="template/navBar.tpl" cache_id=$navbarCache|default:'template|navbar|all'}
</nav> |
category/show.tpl
Code: | {include file="template/bodyUpper.tpl"}
Content comes here
{include file="template/bodyFooter.tpl"} |
It ALWAYS call the cache_id 'template|navbar|all'
If i remove the default it will output the following error:
Code: | Notice: Undefined index: navbarCache in /home/(...)/smarty_internal_templatebase.php(254) : eval()'d code on line 25
Notice: Trying to get property on non-object (...) on line 25
Notice: Undefined index: navbarCache in (...) on line 26
Notice: Trying to get property on non-object (...) on line 26 |
EDIT:
By the way, if i try to print {$navbarCache} it will print 'template|navbar|computer' for example.
If i change the {include} cache_id to someVar and inside navbar.tpl i try to print {$someVar}, it will work as intended. The problem is only on using a $var as cache_id |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Feb 05, 2014 6:57 pm Post subject: |
|
|
I still can't reproduce the problem.
But the error message is exactly the same when the variable at "cache_id=" is not defined. That also explains why you get the default value.
My assumption id that in "cache_id=$navbarCache" the string $navbarCache contains some not visible characters which makes the variable name different and unknown. Try to retype the line.
For another check do:
Code: | <nav role="navigation">
{debug}
{include file="template/navBar.tpl" cache_id=$navbarCache|default:'template|navbar|all'}
</nav> |
You can then check if the value of $navbarCache was passed to the template at all.
What you could also try is to set $smarty->force_compile = true; for a test, to get everything recompiled from scratch. |
|
Back to top |
|
Hept Smarty n00b
Joined: 31 Jan 2014 Posts: 4
|
Posted: Thu Feb 06, 2014 2:27 pm Post subject: |
|
|
I tought something like that at first. Tried rewritting but didn't work.
Then after you posted that, i rewrote again and it worked. Probably something related to bad encoding, idk, as i configured my IDE to use utf-8 and i am taking care about case Sensivity.
Anyway, problem fixed.
But i just found another bug/feature : the cached template DON'T cache the value of $navbarCache ( althrough it cache all other variables ).
Is it expected not to cache the var that is used at cache_id or have i did something wrong ?
I even tried to use inline caching but no good result. Worked-around by always assigning the $navbarCache before displaying...
Edit: BTW, second the {debug}, $navbarCache 'nocache' is set to false |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Thu Feb 06, 2014 7:10 pm Post subject: |
|
|
If you have caching enabled and you specify an cached_id attribute at the {include} tag you indicate the content of the included subtemplate shall be cached in a separate cache file because it's content can expire independent from that of the main template.
Just as one example: with the clearCache() method your can clear all cached content by cache_id.
So it's a feature and not a bug the cache_id attribute at {include} is dynamic. |
|
Back to top |
|
Hept Smarty n00b
Joined: 31 Jan 2014 Posts: 4
|
Posted: Thu Feb 06, 2014 7:14 pm Post subject: |
|
|
I tought so.
Thank you very much! |
|
Back to top |
|
|