Filter condition applyOnTemplates only works if the template is in the URL


How to create a custom filter condition?


Add an implementation of the ExecutionCondition to your filter class:

public MyFilterForTemplate() {
    addCondition(new TemplateCondition());

private class TemplateCondition implements ExecutionCondition {

    public boolean matches(RenderContext renderContext, Resource resource) {
        boolean templateProperty = false;
        boolean templateURL = false;
        Resource main = renderContext.getMainResource();
        for (String template : templateList) {
            if (main.getNode().getPropertyAsString("j:templateName") != null)
                templateProperty = templateProperty | main.getNode().getPropertyAsString("j:templateName").equals(template);
            if (main.getResolvedTemplate() != null)
                templateURL = templateURL | main.getResolvedTemplate().equals(template);
        return templateProperty | templateURL;