问题
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.
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(/.*)?
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?
Thanks!
回答1:
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/[^/]*/[^/]*(/.*)
See demo.
^
- 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
来源:https://stackoverflow.com/questions/34905975/aem-how-to-restrict-a-template-from-showing-in-a-certain-path