Search code examples
aem

How to exclude sub-nodes in an AEM package using filters


I am creating an AEM content package and the resulting zip has the requisite META-INF directory with the filter.xml.

The package has content which is organized like so:

/jcr_root/apps/appgroup/myapp/components
/jcr_root/apps/appgroup/myapp/i18n/en_us.xml
/jcr_root/apps/appgroup/myapp/i18n/es_mx.xml
/jcr_root/apps/appgroup/myapp/templates

The filter.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<workspaceFilter version="1.0">
    <filter root="/apps/appgroup/myapp">
        <exclude pattern="/apps/appgroup/myapp/i18n(/.*)?" />
    </filter>
</workspaceFilter>

Despite having the exclude pattern, the i18n node still gets deployed into the CRX when the package is installed. Shouldn't the filter exclude the i18n node?

Ultimately, I would like to deploy just the en_us node and have the filters block any other languages.

My understanding is that the filter taken into consideration during install and not during compilation. Is this correct?


Solution

  • Filters are applied when the package is built rather than installed. With an exclusion, it shouldn't get installed by your package, but it also means if already present, it also won't get removed either! It should behave as if the package doesn't touch the area covered by the exclude filter.

    From the documentation*:

    • To include all scripts of my application but the forms component:
      • Root path: /apps/myapp
      • Rules: Exclude: /apps/myapp/components/form(/.*)?

    The form component is not included in the package. If such a component already existed when installing the package, CRX would not remove it, because it is not defined by the filters.

    When building the package, all the content defined by each filter is included. When extracting the package, all existing content that matches the filter is removed or replaced.


    Edit: Working from a Maven bundle, you could use specify elements as excluded using a resource declaration, to avoid the content being added to the Zip e.g.:

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <excludes>
                    <exclude>jcr_root/apps/appgroup/myapp/i18n</exclude>
                    <exclude>jcr_root/apps/appgroup/myapp/i18n/**/*.*</exclude>
                </excludes> 
            </resource>
        </resources>
    </build>
    

    It's possible that the filter.xml is getting ignored by Maven on build & once the content is in the package, it's getting installed by CQ regardless.


    EDIT2: * Initial example is no longer in the documentation now that Day.com is down, but should still hold true. Updated documentation is now available here