Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Upgrading from Smarty 2 to latest. Removing $this->

 
Post new topic   Reply to topic    Smarty Forum Index -> Smarty 3
View previous topic :: View next topic  
Author Message
I_am_FeMan
Smarty n00b


Joined: 19 May 2016
Posts: 1

PostPosted: Thu May 19, 2016 12:51 am    Post subject: Upgrading from Smarty 2 to latest. Removing $this-> Reply with quote

As noted in the subject my organization has upgraded to the latest version of Smarty (currently 3.1.29) as a result of upgrading to PHP7. We have a template that contains a navigation bar for the site, as such it is {include}'d in nearly every other template. This template was previously using code similar to:
Code:
{php}
   $this->_tpl_vars["var1"] = phpFunction1();
   $this->_tpl_vars["var2"] = $_SESSION['var2'];
{/php}

Obviously this is no longer supported. What I am wondering though is how to go about getting the information into these template variables without having to go into every .php file to add:
Code:
$smarty->assign('var1', phpFunction());
$smarty->assign('var2', $_SESSION['var2']);

I would prefer to be able to add them just from the template and pass them in from the {assign} tag but with these variables requiring the PHP output is there a way of doing it? Or do I have to modify all the .tpl files and all the .php files?

The problem is just that since this is a menu bar it makes it very tedious to go in and add all the assignment commands in every file that eventually loads a page that displays this menu.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1530

PostPosted: Thu May 19, 2016 2:09 pm    Post subject: Reply with quote

You really should (even MUST) assign variables to the template.
Template shouldn't care about your code structure.
What you really need is a separate block that renders the menu with appropriate caching headers.
And yes, it is a tedious job to cleanup inherently broken application designs, but it pays well in the reduction of the future maintenance costs.
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Tue May 24, 2016 5:48 pm    Post subject: Reply with quote

Code:

{$var1 = phpFunction1()}
{$var2 = $smarty.session.var2}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    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