Jump to:

23000 Posts in 11854 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » replacing content newbie need help

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

Page: 1
Go to End
Author Topic: 650 Views
  • servalman
    Avatar
    Community Member
    211 Posts

    replacing content newbie need help Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: replacing content newbie need help Link to this post

    public SwitchContent(){

    if ($contenttype ...

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

  • servalman
    Avatar
    Community Member
    211 Posts

    Re: replacing content newbie need help Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: replacing content newbie need help Link to this post

    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/

  • servalman
    Avatar
    Community Member
    211 Posts

    Re: replacing content newbie need help Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: replacing content newbie need help Link to this post

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

  • servalman
    Avatar
    Community Member
    211 Posts

    Re: replacing content newbie need help Link to this post

    Hello

    Thanks a lot !!!!

    I'm ok now

    those tools are amazing .

    That was vey nice of you to poit them !

    Thanks

    650 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.