Impose component restriction to a series of parsys-CQ

534 views Asked by At

I have a series of parsys present in my page's footer. At the same time, I want to impose component restriction to all these via etc/designs/projectname/content.xml. This goes like this:

JSP:

    <c:forEach var="i" begin="0" end="${properties.numberOfFooterLinks-1}">
      <div class="small-6 medium-4 large-2 columns">
          <cq:include path="./footerPar${i}"            
                   resourceType="foundation/components/parsys" />
      </div>
    </c:forEach>

XML:

<footer jcr:primaryType="nt:unstructured">
 <footerPar0 jcr:primaryType="nt:unstructured"
            sling:resourceType="foundation/components/parsys"
                 components="[group:footerComp]">
  <section jcr:primaryType="nt:unstructured"/>
  </footerPar0>
</footer>

This works only for the parsys footerPar0 but not for the rest (footerPar1, footerPar2 etc). I am stuck in achieving this. Is there a way to achieve it without repeating the parsys's names till the end of the loop count? Thanks.

1

There are 1 answers

1
anotherdave On BEST ANSWER

I haven't found an elegant way to do this either. One solution is to dynamically remove allowed components using a JavaScript listener & add back in the components that you want to allow.

E.g. overriding parsys itself under /apps/foundation/components/parsys, add an _cq_editConfig.xml, like:

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" 
          xmlns:jcr="http://www.jcp.org/jcr/1.0"
          cq:actions="[_clear]"
          jcr:primaryType="cq:EditConfig">

    <cq:listeners
        jcr:primaryType="cq:EditListenersConfig"
        updatecomponentlist="function(cell, allowed, componentList){
            var firstSearchPath = cell.searchPaths[0];
            var isFooterParsys = firstSearchPath.indexOf('footer/footerPar') > -1;
            if (isFooterParsys && allowed instanceof Array) {
                while(allowed.length > 0) {
                    allowed.pop(); //Remove all currently allowed components from the parsys
                }
                allowed.push('project/components/content/your-component'); //add allowed components
            }
        };"/>
</jcr:root>

Obviously this is quite far reaching, as the listener is affecting all instances of parsys (though targetting your footerPar by name within the function.)

If you don't already have live content in these fields, you could maybe create your own resource type that uses parsys as a supertype, for better level of control.