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

Making a smarty variable (assign) available throughout site.

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


Joined: 14 Nov 2013
Posts: 3

PostPosted: Thu Nov 14, 2013 3:39 pm    Post subject: Making a smarty variable (assign) available throughout site. Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Thu Nov 14, 2013 4:10 pm    Post subject: Reply with quote

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
View user's profile Send private message
miken
Smarty n00b


Joined: 14 Nov 2013
Posts: 3

PostPosted: Thu Nov 14, 2013 7:27 pm    Post subject: SMARTY VARIABLES Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Fri Nov 15, 2013 5:07 am    Post subject: Reply with quote

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
View user's profile Send private message
miken
Smarty n00b


Joined: 14 Nov 2013
Posts: 3

PostPosted: Fri Nov 15, 2013 7:51 am    Post subject: SMARTY VARIABLES Reply with quote

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
View user's profile Send private message
n0aX
Smarty Rookie


Joined: 24 Jan 2011
Posts: 22

PostPosted: Fri Nov 15, 2013 5:02 pm    Post subject: Reply with quote

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
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