Hi SS specialists,
I'm pretty new at Silverstripe and still trying to get my head around the correct (MVC) implementations of things. I was hoping you guys could help me on my way with the following thing I'm trying to implement.
I need to be able to have a tabbed block on a page (I will be using the jQuery UI Tabs) so for this I need to implement 2 structures on a page like:
structure 1:
<ul>
<li><a href="#fragment-1"><span>One</span></a></li>
<li><a href="#fragment-2"><span>Two</span></a></li>
<li><a href="#fragment-3"><span>Three</span></a></li>
</ul>
structure 2:
<div id="fragment-1">
<p>First tab is active by default:</p>
<pre><code>$('#example').tabs();</code></pre>
</div>
<div id="fragment-2">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
</div>
<div id="fragment-3">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
</div>
Basically - structure 1 controls the tabs and structure 2 contains the content of the tabs. For an example see http://jqueryfordesigners.com/demo/tabs.html
This tab block will have to be included on a 'normal' content page. A different Tab block (so different tabs and content) must be included per page.
I was thinking that the easiest way for the content editors to control the content of these tabs would be to be able to add a 'TabContainer' (pagetype) as a child of the page it needs to go on and then add TabContent (pagetypes) to the TabContainer PageType. So in the CMS it would look something like:
Home
- TabsContainer (so child of Home)
-- TabContent 1
-- TabContent 2
Contact Us
About Us
- TabsContainer (so child of About us and different Tab content as Home)
-- TabContent 1
-- TabContent 2
Another Page
Obviousy, the TabContainer and TabContent page types should not show up in the menu so this can be switched off in static_defaults. Here i can also force that a TabContainer can only contain TabContent items. All no problems setting this up so far..
Basically -the content of the Tab should be a normal page that the editors can edit in the CMS, It can contain any HTML element, lists, images, even SWF's so this is the reason why I think the setup as explained should be the easiest for them.
Now... How am I going to do this? Basically - I need to be able to add a Page (TabsContainer including the children TabContents) to it's parent so basically 'Page.ss'.
I have had a look at the NewsArticle example in the tutorial - but this doesn't do what it needs to do as it includes DataObject items, not pages (so also no 'View' in the MVC model) - and in addition to that - the NewArticle example has visual pages (so included in the menu). It also is no good as the News Article are not children of a page but global articles.
I guess I need to do the following after setting up the explained structure as above:
- in the page_controller for mysite/code/Page.php I get a reference to the tabsContainer belonging to the current page so something like:
class Page_Controller extends ContentController {
function getTabContainer(){
$tabContainer = DataObject::get("TabContainer", "ParentID = $this->ID");
}
}
Then in Page.ss, I could maybe (?) use something like:
<% control getTabContainer %>
$Title (should be the Title of the tabContainer as set in the CMS)
<% control Children %> (Should control the children of the TabContainer so the TabContent items...right?)
$content (so the content of the Tab
<% end_control %>
<% end_control %>
However - the above doesn't work.. One reason for this is because the ShowInMenu is set to null and there are no children available. Also - I'm getting a DataObject, which (I guess) means that there is no view (for example a /templates/Layout/TabContent.ss) associated with it..
What is the right way to get this done? I really like to have the CMS structure as described above (so the page that needs a tab container has a child TabContainer with TabContent children). How do I get the views of those TabContainer/Tabcontent(s) inside of any page that inherits from 'Page.ss' ?
Any pointers please? I really think this would be helpful to a lot of people who would like to implement something like this as the output might be a tabcontainer in my particular case - but the principle could be used for a lot of content related features.
Help please ;-)
Best regards,
Mike.