AEM-如何限制模板在特定路径下显示 [英] AEM - How to restrict a template from showing in a certain path
问题描述
我想知道是否有人实现了我将在此处发布的内容。为了允许在特定路径下创建模板,有一个标记 allowedPaths
接收正则表达式。
I wonder if someone has achieved what I'll post here. In order to allow a template to be created under a certain path, there is a flag allowedPaths
that receives a regex.
因此,如果我希望模板测试
仅出现在 / content / www / xx / xx / test-templates
和子元素,我可以这样做:
So, if I want my template "test"
to appear only under /content/www/xx/xx/test-templates
and child elements, I can do this:
/content/www/.*/.*/test-templates(/.*)?
但是如果我想相反的话怎么办?我希望模板 test
出现在每个 / content / www / xx / xx /
节点及以后的节点中,除了 / content / www / xx / xx / test-templates
和孩子?
But what if I want to make the opposite? I want the template "test"
to appear in every /content/www/xx/xx/
node and beyond, EXCEPT /content/www/xx/xx/test-templates
and children?
我尝试了几种方法,但到目前为止没有运气。
I have tried several ways but no luck so far. Do you have some hint regarding this?
谢谢!
推荐答案
您始终可以通过提前限制来限制更通用的模式。这是一个适合您的表达式:
You can always restrict a more generic pattern with a lookahead. Here is an expression that should work for you:
^(?!/content/www/[^/]*/[^/]*/test-templates(?:/|$))/content/www/[^/]*/[^/]*(/.*)
请参见演示。
-
^
-匹配字符串的开头 -
(?!/ content / www / [^ /] * / [^ /] * / test-templates(?:/ | $))
-确保下一个子字符串不是/ content / www /< some_node> /< some_node> / test-templates
,后跟字符串的末尾($
)或/
-
/ content / www / [^ /] * / [^ /] *(/.*)
-匹配/ content / www /< some_node> /< some_node>
,后跟可选的/
以及零个或多个换行符以外的字符
^
- matches the start of string(?!/content/www/[^/]*/[^/]*/test-templates(?:/|$))
- makes sure the next substring is not/content/www/<some_node>/<some_node>/test-templates
, followed by the end of string ($
) or/
/content/www/[^/]*/[^/]*(/.*)
- matches/content/www/<some_node>/<some_node>
followed with optional/
and zero or more characters other than a newline
这篇关于AEM-如何限制模板在特定路径下显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!