17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1048 Views |
-
Accessing cookie values in template

14 June 2008 at 10:05pm Last edited: 14 June 2008 10:05pm
Hi, I have a chunk of code in the Page_Controller on a page type called TourPage, that checks a $_GET value in the URL (from a form submission) and uses that value to set a default currency in the Cookie. (Default is set in Page init()). Code as follows:
class Tour_Controller extends Page_Controller {
function init() {
parent::init();
// If a currency has been selected, update cookie to keep track of user preference
$VivaCurrencyCookie = new Cookie;
if($_GET['viva_cur']) {
$VivaCurrencyCookie->set('viva_currency', $_GET['viva_cur']);
}
}
}
I've tested this and it works fine. But I am unable to work out how to access that cookie value on the template itself. I want to use the cookie value in if conditions to display the correct price. How can you access (or pass to the main class) a variable calculated in a controller?
Cheers
Aaron -
Re: Accessing cookie values in template

14 June 2008 at 10:14pm Last edited: 14 June 2008 10:14pm
Ah, got it - added this function under the init above:
function getCookieCurrency() {
$VivaCurrencyCookie = new Cookie;
return $VivaCurrencyCookie->get('viva_currency');
}
| 1048 Views | ||
|
Page:
1
|
Go to Top |

