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

Using simply jquery (accordion for example)


Reply


5 Posts   2537 Views

Avatar
__fabrice

Community Member, 32 Posts

15 June 2009 at 3:14am

Edited: 15/06/2009 3:15am

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.

Avatar
Hamish

Community Member, 712 Posts

15 June 2009 at 10:35am

Edited: 15/06/2009 10:37am

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

Avatar
__fabrice

Community Member, 32 Posts

15 June 2009 at 7:56pm

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

Avatar
Hamish

Community Member, 712 Posts

15 June 2009 at 9:52pm

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:

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

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

Avatar
__fabrice

Community Member, 32 Posts

16 June 2009 at 9:05am

Edited: 16/06/2009 9:07am

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