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

Nested template and assign question

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


Joined: 23 Mar 2006
Posts: 12

PostPosted: Wed Apr 23, 2008 4:42 pm    Post subject: Nested template and assign question Reply with quote

Im trying to do some mods on an existing product that makes use of smarty templates. The site makes use of a standard template file (lets call it layout.tpl) which basically is the pages header, footer and navigation. Within this template is a variable called $body and depending on what underlying php script is being called the value of $body will change to a variety of other templates.

This all works fine and dandy but I am now trying to make additional variable assignments. These variable assignments are called from the template that ultimately resides in the $body variable of the layout.tpl file.

If I assign variables which are to be displayed in template which will be in the $body variable before the body variable asignment is made everything works fine.

BUT, If I assign variables which are to be displayed in template which will be in the $body variable after the $body variable asignment is made it doesnt work.

for example.....

this works.
$class_tpl->assign('viewdate', $canViewDateAdded); // viewdate variable is inside viewlisting.tpl
$class_tpl->assign('body','viewlisting.tpl'); // body variable is inside layout.tpl
$class_tpl->display('layout.tpl', $user);


this does not work
$class_tpl->assign('body','viewlisting.tpl'); // body variable is inside layout.tpl
$class_tpl->assign('viewdate', $canViewDateAdded); // viewdate variable is inside viewlisting.tpl
$class_tpl->display('layout.tpl', $user);


Am I correct in assuming that when a template is assigned to a variable that any variables called within the template must have a value prior to the assignment for it to be of any use?
Back to top
View user's profile Send private message
Celeb
Administrator


Joined: 17 Apr 2007
Posts: 1025
Location: Vienna

PostPosted: Wed Apr 23, 2008 5:29 pm    Post subject: Reply with quote

I don't see how the order of the assigned template variables can make any difference to the end result. In the way you posted it here both examples should work fine.
_________________
Darn computers always do what I tell them to instead of what I want them to do.
Back to top
View user's profile Send private message
Exitium
Smarty Rookie


Joined: 23 Mar 2006
Posts: 12

PostPosted: Wed Apr 23, 2008 6:11 pm    Post subject: Reply with quote

Celeb wrote:
I don't see how the order of the assigned template variables can make any difference to the end result. In the way you posted it here both examples should work fine.


My initial thought is that it shouldnt matter either but or some reason its not working. Let me elaborate a bit though.

The core product I am working with has embded "hooks" built into the code that we can take advantage of to create modules that work in conjunction with the core product without having to make changes to the core php code.

What I am doing is adding functionality to a given page via these built in hooks. The file I am working on has 2 hooks in it that I can use. These hooks basically call a fnction which is what I have created.

One of these hooks appears early in the code (ie prior to the $body vaiable being assigned a template as its value) and when I make use of this hook the values I assign to template vars within my function are included in the final output.

The problem I face is that the first hook take place in the code before some additional variables are initialized and I really need this data.

Because of that I tried to make use of the second hook which ocures after the $body variable has been assigned a template as a value and right before $class_tpl->display('layout.tpl', $user); is called.

When I take advantage of that hook the aditional data I need is available to my function (which I can verify by echoing or var_dumping it) BUT the data I asign to vaiables within my function is not displayed with the final output.
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Thu Apr 24, 2008 2:10 pm    Post subject: Reply with quote

Assigned SMARTY variables will not be processed before you call the display or fetch methode.

As Celeb did already mention the order of assignments can not be the problem.

Could it be possible that you have caching enabled and you don't see modification?

You could also use the {debug} tag in your layout.tpl to see which variables have been assigned.
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 -> General 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