Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

{include} cache_id not accepting $var

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
Hept
Smarty n00b


Joined: 31 Jan 2014
Posts: 4

PostPosted: Fri Jan 31, 2014 5:11 pm    Post subject: {include} cache_id not accepting $var Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sat Feb 01, 2014 11:44 am    Post subject: Reply with quote

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
View user's profile Send private message
Hept
Smarty n00b


Joined: 31 Jan 2014
Posts: 4

PostPosted: Wed Feb 05, 2014 1:03 pm    Post subject: Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Wed Feb 05, 2014 6:57 pm    Post subject: Reply with quote

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
View user's profile Send private message
Hept
Smarty n00b


Joined: 31 Jan 2014
Posts: 4

PostPosted: Thu Feb 06, 2014 2:27 pm    Post subject: Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Thu Feb 06, 2014 7:10 pm    Post subject: Reply with quote

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
View user's profile Send private message
Hept
Smarty n00b


Joined: 31 Jan 2014
Posts: 4

PostPosted: Thu Feb 06, 2014 7:14 pm    Post subject: Reply with quote

I tought so.

Thank you very much!
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP