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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

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

replacing content newbie need help


Go to End


7 Posts   977 Views

Avatar
servalman

Community Member, 211 Posts

28 July 2010 at 3:22am

Hi

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>
$contentdisplay
<% end_control %>
[c/ode]


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

Avatar
Willr

Forum Moderator, 5523 Posts

28 July 2010 at 9:07pm

public SwitchContent(){

if ($contenttype ...

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

Avatar
servalman

Community Member, 211 Posts

28 July 2010 at 9:12pm

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

Avatar
Willr

Forum Moderator, 5523 Posts

28 July 2010 at 9:30pm

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

[1] http://flowplayer.org/tools/tabs/index.html
[2] http://jqueryui.com/demos/tabs/

Avatar
servalman

Community Member, 211 Posts

28 July 2010 at 9:35pm

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

Avatar
Willr

Forum Moderator, 5523 Posts

28 July 2010 at 11:11pm

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

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

Avatar
servalman

Community Member, 211 Posts

29 July 2010 at 3:15am

Hello

Thanks a lot !!!!

I'm ok now

those tools are amazing .

That was vey nice of you to poit them !

Thanks