Creating an accordion pane in Concrete 5
How to use the built-in jQuery UI to add an accordion to a page type on your concrete5 website.
For an interactive demo of how this works, go here:
How to use the built-in jQuery UI to add an accordion to a page type on your concrete5 website.
For an interactive demo of how this works, go here:
Edit the newly created file, add this where you would like the accordion to appear:
- <div id="accordion">
- <?php
- $sections = $c->getCollectionAttributeValue('accordion_sections');
- foreach ($sections as $opt) {?>
- <h3><?= $opt->value; ?></h3>
- <div>
- <?php
- $a = new Area($opt->value);
- $a->setBlockLimit(1);
- $a->display($c);
- ?>
- </div>
- <? }
- } ?>
- </div>
- <?php
-
-
- class AccordionPageTypeController extends Controller {
-
- public function on_start() {
- $html = Loader::helper('html');
- $this->addHeaderItem($html->css('jquery.ui.css'));
- $this->addHeaderItem($html->css('ccm.dialog.css'));
- $this->addHeaderItem($html->javascript('jquery.ui.js'));
- $this->addHeaderItem($html->javascript('ccm.dialog.js'));
- $js_string = "\n";
- $js_string .= "<script type='text/javascript'>\n";
- $js_string .= " $(function() {\n";
- $js_string .= " $( '#accordion' ).accordion({\n";
- $js_string .=" collapsible: true\n";
- $js_string .= " });\n";
- $js_string .= " });\n";
- $js_string .= "</script>\n";
- $this->addHeaderItem($js_string);
- }
- }
The UI files do not include styling for the h3 tag, so you need to add a little css to get them to look nice:
- #accordion h3 {
- padding: 5px 5px 5px 30px;
- }