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

a short way to Assign a 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 -> General
View previous topic :: View next topic  
Author Message
do_quang_tu
Smarty n00b


Joined: 18 Apr 2003
Posts: 2

PostPosted: Fri Apr 18, 2003 3:39 pm    Post subject: a short way to Assign a var Reply with quote

i wrote a simple function to auto add a var that has the same name-var in Smarty template like this :

Code:

class Smarty_App extends Smarty {

   function x_assign($tpl_var)
          {
              if (is_array($tpl_var)){
               foreach ($tpl_var as $val) {
                    $this->_tpl_vars[$val] = $GLOBALS[$val];
               }
              } else {
                  if ($tpl_var != '')
                   $this->_tpl_vars[$tpl_var] = $GLOBALS[$tpl_var];
              }
          }

}


Usage : $smarty->x_assign("paging");
instead of : $smarty->assign("paging",$paging);
hope you like it
Back to top
View user's profile Send private message Send e-mail
David
Smarty Rookie


Joined: 18 Apr 2003
Posts: 17
Location: New York, NY, USA

PostPosted: Fri Apr 18, 2003 7:36 pm    Post subject: Reply with quote

Ha! Amusing.

I suppose you could also have overridden Smarty's assign() with your own, calling parent::assign() as needed, instead of accessing Smarty's internals.
_________________
David Mintz
http://davidmintz.org/

"Anybody else got a problem with Webistics?" -- Sopranos 24:17
Back to top
View user's profile Send private message
do_quang_tu
Smarty n00b


Joined: 18 Apr 2003
Posts: 2

PostPosted: Sat Apr 19, 2003 6:28 am    Post subject: Reply with quote

Thank you very much , your way's really better . Razz
Back to top
View user's profile Send private message Send e-mail
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