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.

General Questions

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

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

replacing content newbie need help


7 Posts   703 Views


28 July 2010 at 3:22am Community Member, 211 Posts


I have a problem trying to do this :

Replace the value of a variable called $contentdisplay based on the value of a variable called $contenttype and this should be triggered by a link in the template.

So I tried to do it this way.

I created several tabs in cms admin using this to define the :

static $db = array(

'ActifsProduct' => 'HTMLText',
'TextProduct' => 'HTMLText',
'GestesProduct' => 'HTMLText',
'SecretProduct' => 'HTMLText',
'ImageName' => 'Text',

public function getCMSFields()
      $f = parent::getCMSFields();

   $f->addFieldToTab('Root.Content.ActifsProduct', new HtmlEditorField('ActifsProduct'));
   $f->addFieldToTab('Root.Content.TextProduct', new HtmlEditorField('TextProduct'));
   $f->addFieldToTab('Root.Content.GestesProduct', new HtmlEditorField('GestesProduct'));
   $f->addFieldToTab('Root.Content.SecretProduct', new HtmlEditorField('SecretProduct'));
   $f->addFieldToTab('Root.Content.Main', new TextField('ImageName'), 'Content');
      return $f;


Then in my controler I did this

class ProductPage_Controller extends Page_Controller

public SwitchContent(){

if ($contenttype == 'content01')
{$contentdisplay = $this ->TextProduct};
elseif ($contenttype == 'content02')
{ $contentdisplay = $this ->GestesProduct};
elseif ($contenttype == 'content03')
{ $contentdisplay = $this ->SecretProduct};

else {$contentdisplay = $this ->ImageName};
return $contentdisplay


finally in my template I got this

<% control SwitchContent %>

<div id="NavDescriptif">
<li><a href="$Link?$contenttype='content01' " class="$LinkingMode">content01</a></li>
<li><a href="$Link?$contenttype='content02' " class="$LinkingMode">content02</a></li>
<li><a href="$Link?$contenttype='content03 " class="$LinkingMode">content01</a></li>
<% end_control %>

I really need a hand on this because my project is stuck...

I get a syntax error on the php code part

Thanks a lot for your help


28 July 2010 at 9:07pm Forum Moderator, 5511 Posts

public SwitchContent(){

if ($contenttype ...

You have not defined $contenttype anywhere before in that function so of course PHP will throw an error.


28 July 2010 at 9:12pm Community Member, 211 Posts

oups I made a mistake copying my code it is suposed to be :

public function SwitchContent() {...}

But in fact I feel I'm not doing this the right way.

I had another answer on some other point telling me that to do what i wanted ( displaying tabbed content) I should use Jquery.

What do you suggest can I do it without Jquery or not ?

Thank you


28 July 2010 at 9:30pm Forum Moderator, 5511 Posts

You can always write jQuery to display the tabs for you but jQuery tools [1] and jQuery UI do provide tabbing functionality out of the box



28 July 2010 at 9:35pm Community Member, 211 Posts

Thanks a lot Willr

I will take a look at this but it seems quite easy to use.

I will try this today and let you know how it goes but I think you saved me ;)

One more question do I have to install Jquery in SS or is it provided with it I'm currently using 2.4 stable

Thanks Again


28 July 2010 at 11:11pm Forum Moderator, 5511 Posts

SS 2.4 includes jQuery 1.4.2 in the download. To include it on your webpage you can do the following in your

<% require javascript(sapphire/thirdparty/jquery/jquery.js %>


29 July 2010 at 3:15am Community Member, 211 Posts


Thanks a lot !!!!

I'm ok now

those tools are amazing .

That was vey nice of you to poit them !