Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Variables only displaying when page is refreshed

Go to End

3 Posts   830 Views


Community Member, 19 Posts

1 November 2012 at 11:30pm


I asked this in a different section, but haven't received a reply in almost a week.

Since asking, I have modified it a bit, but still only works when refreshing the page.

I am trying to get a variable from various google location ads to change the phone number depending on the ?number=xxx from the ad.

Currently the number displays a default value unless the page is refreshed, then the variable is displayed.
I need it to display the number without the need for a refresh.

Is there a better way of doing this that will display the variable number without the need for a page refresh?


<% if phonenumber %>$phonenumber <% else %>0800 xxx xxx<% end_if %>

In page.php
public function Phonenumber() {
    if (!isset($_SESSION['number']))
$phonenumber = $_GET['number'];
$_SESSION['number'] = $phonenumber;
return strip_tags (Session::get ('number'));

Any advice or pointers are massively appreciated.


Forum Moderator, 5523 Posts

2 November 2012 at 11:24am

You might be better writing that function as

$number = Session::get('number');

if($get = $this->request->getVar('number')) {
$number = $get;
Session::set('number', $get);

return Convert::raw2xml($number);


Community Member, 19 Posts

3 November 2012 at 12:54am

Willr, thanks. That has fixed all my woes.
Except the admin section is white screening with no error being thrown.

I created a different page type and put this function on there instead of page.php and the admin section is accessible again.

One more question, is it possible to use a field in the CMS that can be used as the variable?

$fields->addFieldToTab('Root.Content.Main', new TextField('StaticNumber'), 'Content');

is this possible?