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

Assigned Variables not accessible in sub-template?

 
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 -> Smarty 3
View previous topic :: View next topic  
Author Message
arT2
Smarty Rookie


Joined: 14 Oct 2009
Posts: 7
Location: Switzerland

PostPosted: Sun Dec 06, 2009 11:16 pm    Post subject: Assigned Variables not accessible in sub-template? Reply with quote

hello there,

first of all a little bit of code for better understanding. it's pretty simple.

i use Smarty 3.0b5.
caching: 2


_framework.tpl - this is what i display() in the end
Code:
<html>
...

{include file="{$module}.tpl"}
{include file="_auth_form.tpl"}

...
</html>



_auth_form.tpl - works fine
Code:

<form action="{$mrp}" method="post">
    {nocache}
        {if $smarty.session.logged_in === true}
            <fieldset>
                <legend>{$L.HELLO|capitalize} {$smarty.session.username}</legend>
                <input type="submit" name="submit_logout" value="{$L.LOGOUT}" />
            </fieldset>
        {else}
            <fieldset>
                <legend>{$L.LOGIN|capitalize}</legend>
                u: <input type="text" name="username" size="5" /><br />
                p: <input type="password" name="password" size="5" /><br />
                <input type="submit" name="submit_login" value="&raquo;" />
            </fieldset>
        {/if}
    {/nocache}
</form>



radio.tpl - buggy
Code:
<p>
   {nocache}
      current song: {$current_song|escape:htmlall}<br />
      recent history:<br />
      {foreach key=k item=i from=$song_history}
         {$i.playedat|date_format:$conf.time.ftime} | {$i.title|escape:htmlall}<br />
      {/foreach}
   {/nocache}
</p>



okay now what is exactly bugged in radio.tpl? when i reload the page to get the cached version wich still should include the "live" variables" from the {nocache} block, the variables are just not appearing in the output. but again, i see them in the debug window with "live" values.

for example, look in _auth_form.tpl at the variable $L wich is for i18n or even $smarty.session.username. they are, like the variables for radio.tpl, in the debug window with correct values.

so why can't i reach $current_song and $song_history in radio.tpl?

hope you understand my english Rolling Eyes
and thanks in advance for reading!


greetings
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Mon Dec 07, 2009 4:14 pm    Post subject: Reply with quote

Are you using $smarty->is_cached(...) to check if a valid page is in cache?

All nochache variables have to be assigned before the is_cached call.

is_cached has to load the page for getting access to the file
dependency in formation. For performance in case that the page is
still valid the result is kept for the later fetch or display call.
Otherwise we would have to read the page twice.

FYI this is same behaviour as in Smarty 2
Back to top
View user's profile Send private message
arT2
Smarty Rookie


Joined: 14 Oct 2009
Posts: 7
Location: Switzerland

PostPosted: Sun Dec 20, 2009 8:13 am    Post subject: Reply with quote

hey,
thanks for the reply. i just wasn't working on the project in the last 2 weeks. so i'm a bit late now.

so, yes i was using is_cached() on the wrong place. just realized it too late. sorry.

anyway, i've read the "template inheritance" section in the readme now and i think i wanna use this nice method.

so i played around with the example and it works fine. just when i come to the part where i want to use is_cached() to prevent some heavy stuff from being exec.

so before i waste another hour i just ask:
can i check also with is_cached() when i do display('extends:framework.tpl|home.tpl|home_sidebar.tpl') or do i have to do something different? (i have a cache_group and compile_id just like before)

didn't find anything about is_cache() and display('extends:...') :/


thanks in advance for reading


ps: when i use the other templating method where i include "home.tpl" in framework.tpl and just display(framework.tpl), is_cached() works fine.
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Mon Dec 21, 2009 7:08 pm    Post subject: Reply with quote

is_cache() does work for all resources. So it should work.
Back to top
View user's profile Send private message
arT2
Smarty Rookie


Joined: 14 Oct 2009
Posts: 7
Location: Switzerland

PostPosted: Mon Dec 21, 2009 11:03 pm    Post subject: Reply with quote

thanks!
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 -> Smarty 3 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