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, Ed, biapar, Willr, Ingo, swaiba

Accordion function

Go to End

3 Posts   2610 Views


Community Member, 3 Posts

22 April 2009 at 10:13am

Edited: 22/04/2009 10:14am

We would like to use an accordion function in a SilverStripe website similar to, but are not sure how this would be set up to allow editing in the CMS. Has this been done before or are there any ideas?


Community Member, 904 Posts

22 April 2009 at 8:44pm

Edited: 22/04/2009 8:48pm

An accordion can be realized with just templates, css and javascript. As for the CMS: You could simply create sub-pages for each of the accordion panes. Then output it in your template like so:

<% if Children %>
<div class="accordion">
	<% control Children %>
		<h2 class="accordion-header">$Title</h2>
	<% end_control %>
<% end_if %>

That would output the contents of all child-pages of the current page. Then it's just a matter of applying CSS and JavaScript for a fully working accordion.

Edit: if there are only small amounts of content in the accordion tabs, you could also use something like a has_many relation or even enter the required code inside the editor. There are quite a lot of possible solutions.. it's all a matter of taste.
On a second thought, the has_many relation is probably even better than my first solution, since it won't actually require a page for each accordion pane (therefore not polluting the url names)


Community Member, 3 Posts

23 April 2009 at 4:26pm

Thank you, brilliant