|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
I_am_FeMan Smarty n00b
Joined: 19 May 2016 Posts: 1
|
Posted: Thu May 19, 2016 12:51 am Post subject: Upgrading from Smarty 2 to latest. Removing $this-> |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Thu May 19, 2016 2:09 pm Post subject: |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue May 24, 2016 5:48 pm Post subject: |
|
|
Code: |
{$var1 = phpFunction1()}
{$var2 = $smarty.session.var2}
|
|
|
Back to top |
|
|
|
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
|