|
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 |
miken Smarty n00b
Joined: 14 Nov 2013 Posts: 3
|
Posted: Thu Nov 14, 2013 3:39 pm Post subject: Making a smarty variable (assign) available throughout site. |
|
|
Only started Smarty today! Can someone please tell me how to make a smarty variable available to all pages in my site. I get the site name from a table in the start page, then I want that value available on all subsequent pages. I found some syntax re smarty->assign with the global keyword but could not get it to work. Thank you. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Thu Nov 14, 2013 4:10 pm Post subject: |
|
|
If you make the normal $smarty->assign('foo','bar');
The template variable $foo is available to all calls of $smarty->fetch(), $smarty->display() and subtemplates called by the {include....} tag. |
|
Back to top |
|
miken Smarty n00b
Joined: 14 Nov 2013 Posts: 3
|
Posted: Thu Nov 14, 2013 7:27 pm Post subject: SMARTY VARIABLES |
|
|
Hi,
Thank you for the quick response, and I think I understand the answer, but the situation I have is this. I get a value on page1.php from MySQL database, assign to smarty and display a smarty template that uses the value, successfully. But then I have links in that template that open other php pages that also display smarty templates, and it is in those templates that I want to use the original variable.
mindex.php, gets value, displays mindex.tpl, has a link to resort.php which displays resort.tbl, resort.tbl needs access to the original variable. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Fri Nov 15, 2013 5:07 am Post subject: |
|
|
For Smarty these are completely independent requests.
If it's just a short value you could pass the value as $_GET parameter in the link. |
|
Back to top |
|
miken Smarty n00b
Joined: 14 Nov 2013 Posts: 3
|
Posted: Fri Nov 15, 2013 7:51 am Post subject: SMARTY VARIABLES |
|
|
Ok, that's clear. I really just wanted to make sure that I was not missing something, like a 'global variable cache' or so on. I think I will use a header template in each page template, having thought about it more sub-templates would seem the obvious way to support common content. Thank you very much for your help. |
|
Back to top |
|
n0aX Smarty Rookie
Joined: 24 Jan 2011 Posts: 22
|
Posted: Fri Nov 15, 2013 5:02 pm Post subject: |
|
|
If it is not multiple server environment with clusters, you can use sessions and access the variable by $_SESSION as well. This can be better than writing the variable in url for all get requests. |
|
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
|