May 22, 2020
Estimated Post Reading Time ~

How to wrap 2 components in a div from the template content.xml file?

I have two components that should be configured in a cq template, in the content.xml file (in the jcr:content node). I don't have a page component for my template, so I cannot do something like this:

<div class="wrapper_div">
   <cq:include resourceType="/my/first/component"/>
   <cq:include resourceType="/my/second/component"/>
</div>
Is there a way to define a div container from within content.xml?

Best How To:
There can be one trick, you can add below to the content.xml file of your template.

  <jcr:content
        jcr:primaryType="cq:PageContent"
        sling:resourceType="path/of/page/page-component">
        <par
            jcr:primaryType="nt:unstructured"
            sling:resourceType="foundation/components/parsys">
            <simple
                jcr:lastModified="{Date}2015-05-05T12:16:19.895+05:30"
                jcr:lastModifiedBy="admin"
                jcr:primaryType="nt:unstructured"
                sling:resourceType="path/components/content/component1"/>
            <simple1
                jcr:lastModified="{Date}2015-05-05T12:16:19.895+05:30"
                jcr:lastModifiedBy="admin"
                jcr:primaryType="nt:unstructured"
                sling:resourceType="path/components/content/component2"/>
        </par>
    </jcr:content>
</jcr:root>
This will create the content nodes for the page using this template, but to make this work you must have parsys included in your rendering page component path/of/page/page-component e.g. <cq:include path="par" resourceType="foundation/components/parsys" />

Also there are some other ways like to add node of cq:template under your page component to pre-populate the components.


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.