Jump to:

23372 Posts in 18175 Topics by 2865 members

General Questions

SilverStripe Forums » General Questions » Using simply jquery (accordion for example)

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: 2438 Views
  • __fabrice
    Avatar
    Community Member
    32 Posts

    Using simply jquery (accordion for example) Link to this post

    Hi,

    I try to use Jquery with silverstripe, but I don't know how to access the html elements in the $Content var (in .ss).

    So, in m controller class :

    function init() {
    Requirements::javascript('jsparty/jquery/jquery.js');
    parent::init();
    }

    I try this successfully (of course) :

    <script type="text/javascript">

       $(document).ready(function() {
          alert('hi');
       });

    </script>

    <div id="Content" class="typography">
    $Content
    </div>

    But I want to use the accordion jquery plugin .The html code is in the $Content variable. I think I don't use this variable and copy the html code directly in the .ss file ?.

    It's the right way to do ?

    Thanks,
    Fabrice.

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Using simply jquery (accordion for example) Link to this post

    $Content is purely a server side construct. JavaScript works on the client side - ie, the generated code. Open your page with your browsers 'show source' tool and you'll see the actual HTML that is presented to the browser.

    The html code is in the $Content variable

    What doe that mean? $Content is the text entered by the user in the CMS content field, formatted for xhtml. You shouldn't need to know what it is to make any javascript work.

  • __fabrice
    Avatar
    Community Member
    32 Posts

    Re: Using simply jquery (accordion for example) Link to this post

    Hi,

    Thanks for your answers, but I know all of this. For example, all the text in $Content variable must be "split" in 3 parts, 'cause my accordion (jquery.ui) have 3 parts, 3 div, 3 href ... etc...

    So, I copy all the text in the .ss file, and include directly the jquery code, and it's fine. But, finally, the CMS isn't usefull, because I can't change the content in the CMS, only in the .ss file .

    Thanks,
    Fabrice

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Using simply jquery (accordion for example) Link to this post

    There are two parts - the template (your .ss files - these don't change regularly) and the site content.

    It sounds like you want to edit your template - so yes, you will have to edit the .ss files. That is exactly what they're for. You create your template, with your JavaScript, to make the site appear and behave the way you want. Then, you use the Content Management System to.. ahem.. manage the content.

    The text from $Content is the stuff that you type into the page content field. It is not intended to be the HTML for the entire page.

    If you have not already done the tutorials, now would be a good time:

    http://doc.silverstripe.com/doku.php?id=tutorials

    Maybe you could be more specific about what you are trying to do. Are you trying to create a menu system, for example?

  • __fabrice
    Avatar
    Community Member
    32 Posts

    Re: Using simply jquery (accordion for example) Link to this post

    Hi,

    With this messages, I begin to tought that my question isn't clear, or stupid
    In the $Content var, I have this :

    - Section 1
    blabla of section 1

    - Section 2
    blabla of section 2

    - Section 3
    blabla of section 3

    And I want this :

    <div id="accordion">
       <h3><a href="#">Section 1</a></h3>
       <div>
          <p>blabla of section 1</p>
       </div>
       
       <h3><a href="#">Section 2</a></h3>
       <div>
          <p>blabla of section 2</p>
       </div>
       
       <h3><a href="#">Section 3</a></h3>
       <div>
          <p>blabla of section 3</p>
       </div>
    </div>


    And it's now it's seems obvious that I can't do this with the $Content variable.

    Fabrice

    2438 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.