Adobe CQ components restricting child components

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.

+6
source share
2 answers

The solution here is to use parsys and build the composite component to limit the content of the accordion to just a set of components (as described in the blog post).

See http://localhost:4502/content/geometrixx/en/company/press/asseteditor.html , which also uses this method for the component dam/components/asseteditor/thumbnail .

0
source

This is a very common problem in AEM. There are several ways to deal with this, depending on the needs of your business and how your design will display this. I can offer two solutions for this: 1. Apply a template design constraint to your accordion component. This means that you drop the accordion component, and then switch to page design mode in the accordion paired component of the accordion component. This is a one-time job.

Although I would recommend option number 2: 2. In the dialog box of the accordion component, ask the author to add an accordion element using a multilist. - To add a new element, simply open the accordion dialog and add the element to the multi-sheet and enter the accordion symbol in it. - To remove an item, open the dialog box and remove the item from the multilist. - To change the position, reorder the items in multi-sheets. Based on the absence of multi-sheeted elements entered by the author in the Accordion dialog box, statically include the component of the accordion component and indicate the identifier of the component entered by the author in multi-sheets.

Using this approach, you can easily restrict the component in the accordion. - Reduce one component (accordion element) in sidekick - Reduce one parsia per page (so many parsys feed authoring performance)

0
source

Source: https://habr.com/ru/post/945511/


All Articles