I am trying to create a component for a simple accordion where content blocks are stored under the headers and only one title is displayed at a time. My preferred implementation uses two components: one for representing the entire accordion and a second for one record.
The idea is that the author of the content can pull the accordion out of the sidekick and then drop one or more elements of the accordion into the accordion, but not allow other components to be dropped here. Accordion elements should only be available in the accordion component, and not in any other pairs.
My problem is that currently I can add other content to the accordion and add accordion elements outside the accordion.
First attempt to solve this problem:
foobar/components/accordion foobar/components/accordion/accordion.jsp foobar/components/accordion/cq:editConfig foobar/components/accordion/dialog foobar/components/accordion/accordionitem foobar/components/accordion/accordionitem/accordionitem.jsp foobar/components/accordion/accordionitem/cq:editConfig foobar/components/accordion/accordionitem/dialog
Here are the configuration files from this:
accordion /.content.xml
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" cq:isContainer="{Boolean}true" jcr:primaryType="cq:Component" jcr:title="Accordion" sling:resourceSuperType="foundation/components/parbase" allowedChildren="[*/accordion/accordionitem]" allowedParents="[*/parsys]" componentGroup="General"/>
accordion /_cq_editConfig.xml
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" cq:actions="[-,edit,-,delete]" cq:layout="editbar" jcr:primaryType="cq:EditConfig"> <cq:listeners jcr:primaryType="cq:EditListenersConfig" aftercopy="REFRESH_PAGE" afterdelete="REFRESH_PAGE" afterinsert="REFRESH_PAGE"/> </jcr:root>
The dialog is empty and exists only for the component to appear in the sidekick.
accordion.jsp just includes the basics palette.
accordion /accordionitem/.content.xml
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" jcr:primaryType="cq:Component" jcr:title="Accordion Item" sling:resourceSuperType="foundation/components/parbase" allowedParents="[*/accordion]" componentGroup="General"/>
The title bar of the accordion element title. EditConfig just adds a toolbar but does not listen.
accordionitem.jsp displays the name taken from the dialog and has parse.
My problem is that parsys do not use the rules for accordion and accordion components. Instead, they seem to inherit from the next parsys, rather than being overwritten.
I can correctly install the components using the editing mode on the page and selecting the appropriate components, but this sets the information against the template, that is, I need to perform the same configuration for each page template. I want it defined in the component definition instead, so that it exists once.
After writing the components for the first time, I found this blog that describes exactly the same scenerio: http://jenikya.com/blog/2012/03/cq5-accordion-component.html
Using this as a reference, I tried to add the parsys extension for use in accordion.jsp instead. It didn't make any difference to the code, so even my custom parsys allowed me to add components other than the accordion element.
Any recommendations regarding what is wrong or other approaches are welcome.