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

Accessing smarty variable in the {php} block

 
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
aladar
Smarty n00b


Joined: 30 May 2003
Posts: 2

PostPosted: Fri May 30, 2003 3:42 am    Post subject: Accessing smarty variable in the {php} block Reply with quote

Is there an way to access smarty variable in the {php} {/php} block? I've glance through the FAQ and Smarty Doc, but couldn't find an answer. One ugly way is to use the SESSION variable, but that defeats the purpose of using smarty variable.

Thanks for the help,
Scott Seong
Back to top
View user's profile Send private message
Wom.bat
Smarty Pro


Joined: 24 Apr 2003
Posts: 107
Location: Munich, Germany

PostPosted: Fri May 30, 2003 2:54 pm    Post subject: Reply with quote

doesn't $this work?
Back to top
View user's profile Send private message
aladar
Smarty n00b


Joined: 30 May 2003
Posts: 2

PostPosted: Fri May 30, 2003 3:28 pm    Post subject: Reply with quote

$this works...

To be exact, I had to use $this->_tpl_vars['variable'].

Thanks much!
Scott
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Fri May 30, 2003 3:49 pm    Post subject: Reply with quote

even cleaner would be
$var = $this->get_template_vars('variable');

if you want to change those variables obtain a reference:
$var = &$this->get_template_vars('variable');

see:
http://smarty.php.net/manual/en/api.get.template.vars.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Fri May 30, 2003 5:40 pm    Post subject: Reply with quote

@messju: is there a reason that a reference isn't always returned by get_template_vars?
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Fri May 30, 2003 7:15 pm    Post subject: Reply with quote

@boots: the reason is simply that it is not possible in php. the function returns a reference, but the '='-operator performs a copy. you allways have to request a reference explicetly with the &-operator in the assignment.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Fri May 30, 2003 7:38 pm    Post subject: Reply with quote

Embarassed of course, doh. Sorry!!

I think I've gotten very used to using static classes where I pass by reference the object that I want filled (or molded) with the function results. ( eg: myclass::getvars( $myvarobj, $var ); ) This avoids the usual trickery involved with PHP return types and assignment and for me, helps me separate my data and purely functional classes. In fact, I usually setup the function return values to be either True/False or an integer return code.

As always thanks for the reply and setting me straight!
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