在我的页面页脚中有一系列parsys。同时,我想通过etc/designs/projectname/content.xml对所有这些施加组件限制。它是这样的:
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>
这只适用于parsys footerPar0,但不适用于其他(footerPar1, footerPar2等)。我一直在努力实现这个目标。有没有一种方法来实现它,而不重复parsys的名称,直到循环计数结束?谢谢。
我也没有找到一种优雅的方法来做到这一点。一种解决方案是使用JavaScript侦听器动态删除允许的组件。添加回您想要允许的组件。
。在/apps/foundation/components/parsys
下重写parsys本身,添加_cq_editConfig.xml
,如:
<?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>
显然,这是相当深远的,因为侦听器影响parsys的所有实例(尽管在函数中通过名称针对您的footerPar)。
如果这些字段中还没有活动内容,您可以创建自己的资源类型,使用parsys作为父类型,以获得更好的控制级别。