AEM - 如何限制模板在特定路径中显示

AEM - How to restrict a template from showing in a certain path

我想知道是否有人已经实现了我在这里 post 的目标。为了允许在特定路径下创建模板,有一个标志 allowedPaths 接收正则表达式。

所以,如果我希望我的模板 "test" 只出现在 /content/www/xx/xx/test-templates 和子元素下,我可以这样做:

/content/www/.*/.*/test-templates(/.*)?

但如果我想反其道而行之怎么办?我希望模板 "test" 出现在每个 /content/www/xx/xx/ 节点及以后,除了 /content/www/xx/xx/test-templates 和 children?

我尝试了几种方法,但到目前为止都没有成功。你对此有什么提示吗?

谢谢!

您始终可以通过先行限制更通用的模式。这是一个适合您的表达式:

^(?!/content/www/[^/]*/[^/]*/test-templates(?:/|$))/content/www/[^/]*/[^/]*(/.*)

参见demo

  • ^ - 匹配字符串的开头
  • (?!/content/www/[^/]*/[^/]*/test-templates(?:/|$)) - 确保下一个子字符串不是 /content/www/<some_node>/<some_node>/test-templates,后跟字符串结尾 ($) 或 /
  • /content/www/[^/]*/[^/]*(/.*) - 匹配 /content/www/<some_node>/<some_node> 后跟可选的 / 和除换行符
  • 以外的零个或多个字符