Expand my Community achievements bar.

Nomination window for the Adobe Community Advisor Program, Class of 2025, is now open!

Render condition for page dialog property

Avatar

Level 9

Hello Team,

 

I have a page property checkbox, that should be visible only in my language pages.

example: 

/content/abc/us/en
/content/abc/us/fr
/content/abc/gb/en

It should not be visible for other projects. (Since the editable template is used for other projects too)

property should be visible in 4th node. i.e /content/abc/us/en not in other child pages. example: /content/abc/us/en/home/service

 

I tried this logic. But this is failing. Can someone help me?

<isMyCheckbox
                                        jcr:primaryType="nt:unstructured"
                                        sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
                                        text="Is ABC"
                                        name="./istesting"
                                        value="{Boolean}true"
                                        uncheckedValue="{Boolean}false"
                                        checked="{Boolean}false">
                                        <granite:rendercondition
                                            jcr:primaryType="nt:unstructured"
                                            sling:resourceType="granite/ui/components/coral/foundation/renderconditions/and">
                                            <conditions
                                                jcr:primaryType="nt:unstructured"
                                                sling:resourceType="granite/ui/components/coral/foundation/renderconditions/property"
                                                propertyName="path"
                                                propertyValue="/content/abc"/>
                                            <conditions
                                                jcr:primaryType="nt:unstructured"
                                                sling:resourceType="granite/ui/components/coral/foundation/renderconditions/property"
                                                propertyName="pathSegmentCount"
                                                propertyValue="4"/>
                                        </granite:rendercondition>
                                    </isMyCheckbox> 

 

cc @arunpatidar  @AmitVishwakarma @SureshDhulipudi @Raja_Reddy 

7 Replies

Avatar

Level 4

hi @Mahesh_Gunaje ,

Hope you have find a solution for the above ask. If not few options below.

1. We can create a custom template for those specific language pages and add the checkbox in that template so it will be unique

2. you can write a custom java script and include that in a client library. Ensure the client library is of the cq.authoring.dialog category.

and add the client library in the component dialog 

extraClientlibs (String[]) = ["your-project.components.page.clientlibs"]

 

Avatar

Community Advisor

Hi @Mahesh_Gunaje 

I saw your question about the AEM page property checkbox, and I think I can help you out. You want it to show up only on specific language pages like /content/abc/us/en, /content/abc/us/fr, and /content/abc/gb/en (at the 4th level), but not on deeper pages like /content/abc/us/en/home/service or in other projects using the same editable template. Your current logic is a good start, but it’s not quite working, right? Let’s figure this out together!

What’s Going Wrong

From what you shared, you’re using a granite/ui/components/coral/foundation/renderconditions/and with two conditions:

  • Checking if the path starts with /content/abc — this part’s fine, but it’s too broad since it’ll match deeper pages too.
  • Using pathSegmentCount to limit it to level 4 — problem is, pathSegmentCount isn’t something Granite UI recognizes out of the box, so that’s probably why it’s failing.

A Simpler Fix

I’d suggest using a regex-based render condition. It’s quick, doesn’t need custom code, and should do exactly what you want. Here’s how I’d tweak your dialog XML:

<isMyCheckbox
    jcr:primaryType="nt:unstructured"
    sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
    text="Is ABC"
    name="./istesting"
    value="{Boolean}true"
    uncheckedValue="{Boolean}false"
    checked="{Boolean}false">
    <granite:rendercondition
        jcr:primaryType="nt:unstructured"
        sling:resourceType="granite/ui/components/coral/foundation/renderconditions/regex"
        expression="^/content/abc/[a-z]{2}/[a-z]{2}$"/>
</isMyCheckbox>

Why This Works


The regex render condition checks the page path against a pattern:

  • ^/content/abc makes sure it starts with /content/abc.
  • [a-z]{2} matches a 2-letter country code (like us or gb).
  • [a-z]{2} matches a 2-letter language code (like en or fr).
  • $ ensures it stops there — no extra levels like /home.
  • So, it’ll work for /content/abc/us/en but not /content/abc/us/en/home or /content/xyz/us/en.

If You Want More Control

If regex feels too rigid or you think you’ll need fancier logic later, you could go with a custom render condition. I’ve done this before — you’d create a little Sling model under /apps to check the path exactly how you want. Something like:

  1. Add a node in /apps/myproject/components/renderconditions/languagePageCondition.
  2. Write a quick Java class to check the path (I can share code if you need it!).
  3. Point your dialog to that custom condition.

But honestly, unless you need something super specific, the regex trick should be plenty.

Try It Out

Pop that XML into your dialog, deploy it, and test it on a few pages:


  • /content/abc/us/en — checkbox should show up.
  • /content/abc/us/en/home — should be hidden.
  • /content/xyz/us/en — hidden too.

Let me know how it goes! If it’s still not working, maybe we can dig into your setup a bit more — like, are there any funky inherited properties or template overrides messing things up?


Thanks

Avatar

Level 9

Hi @partyush 

Thanks for your quick help.

To be frank, my project has this structure

/content/abcd/efgh/xyz/{country-code}/{language-code}

{country-code}: Not just 2 character

I have used below logic. Still, not working. Not sure what I am missing.

<isMyCheckbox
                                        jcr:primaryType="nt:unstructured"
                                        sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
                                        text="Is ABC"
                                        name="./istesting"
                                        value="{Boolean}true"
                                        uncheckedValue="{Boolean}false"
                                        checked="{Boolean}false">
                                        <granite:rendercondition
                                            jcr:primaryType="nt:unstructured"
                                            sling:resourceType="granite/ui/components/coral/foundation/renderconditions/regex"
                                            expression="^/content/abcd/efgh/xyz/[a-z]+/[a-z]{2}$"/>
                                    </isMyCheckbox> 

Avatar

Community Advisor

Given your project structure /content/abcd/efgh/xyz/{country-code}/{language-code} where {country-code} is not just 2 characters (e.g., usa, india) and {language-code} is 2 characters (e.g., en, fr), and the checkbox should only appear at this exact 5th node level (not deeper), here’s why your logic might be failing and how to fix it.

    1. Case Sensitivity: Your regex ^[a-z]+/[a-z]{2}$ assumes lowercase. If your paths have uppercase (e.g., USA, EN), it won’t match.
    1. Dialog Path Context: In a page properties dialog, the path might include /jcr:content (e.g., /content/abcd/efgh/xyz/usa/en/jcr:content), and your regex doesn’t account for this optional suffix.
    1. Regex Scope: Your regex correctly targets the 5th node, but it might not be evaluating the path you expect—verify the resource path in the dialog.
    • {country-code}: Variable length, mixed case (e.g., usa, India).
    • {language-code}: 2 characters, mixed case (e.g., en, FR).
    • Only 5th node (e.g., /content/abcd/efgh/xyz/usa/en), not deeper (e.g., /content/abcd/efgh/xyz/usa/en/home).
      <isMyCheckbox
          jcr:primaryType="nt:unstructured"
          sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
          text="Is ABC"
          name="./istesting"
          value="{Boolean}true"
          uncheckedValue="{Boolean}false"
          checked="{Boolean}false">
          <granite:rendercondition
              jcr:primaryType="nt:unstructured"
              sling:resourceType="granite/ui/components/coral/foundation/renderconditions/regex"
              expression="^/content/abcd/efgh/xyz/[A-Za-z]+/[A-Za-z]{2}$"/>
      </isMyCheckbox>

      If it still doesn’t work:

      1. Check the Path: Add a log statement or use AEM’s debugger to confirm the exact path being evaluated (e.g., /content/abcd/efgh/xyz/usa/en or /content/abcd/efgh/xyz/usa/en/jcr:content).

Avatar

Level 9

Hi @partyush  @arunpatidar 

Sorry for late reply. Tried below options. Still, no luck.

I dont want to use any custom servlet option.

 

My lang code path is here.

/content/abcd/efgh/xyz/{country-code}/{language-code}
 
{country-code}: Not just 2 character
 
Solution 1:
<granite:rendercondition
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/renderconditions/simple"
expression="path.startsWith('/content/abcd/efgh') &amp;&amp; path.split('/').length == 6"/>
 
 
Solution 2:
<granite:rendercondition
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/renderconditions/and">
 
<condition1
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/renderconditions/simple"
expression="path.startsWith('/content/abcd/efgh')"/>
 
<condition2
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/renderconditions/simple"
expression="path.split('/').length == 6"/>
 
</granite:rendercondition>
 
Note: /content/abcd/efgh  Since, the same page template(component) is used in other project
 
Thanks
 
 
 

Avatar

Community Advisor

Hi @Mahesh_Gunaje 

path.startsWith('/content/abcd/efgh') expression will not work with page properties because because page property url does not start with /content.

you need to try with something like below

<granite:rendercondition
         jcr:primaryType="nt:unstructured"
         sling:resourceType="/libs/granite/ui/components/coral/foundation/renderconditions/simple"
         expression="${paramValues["item"][0] == "/content/abc/us/en" || paramValues["item"][0] == "/content/abc/us/fr"  || paramValues["item"][0] == "/content/abc/gb/en" }"/>

for dynamic logic you can rely on 

granite:relativeParent("/a/b/c/d", 1) == "/a/b/c"

 Example

granite:relativeParent(paramValues["item"][0], 4) == ""

 



Arun Patidar

Avatar

Community Advisor

Hi @Mahesh_Gunaje 

You can try below


 

<granite:rendercondition
         jcr:primaryType="nt:unstructured"
         sling:resourceType="/libs/granite/ui/components/coral/foundation/renderconditions/simple"
         expression="${paramValues["item"][0] == "/content/abc/us/en" || paramValues["item"][0] == "/content/abc/us/fr"  || paramValues["item"][0] == "/content/abc/gb/en" }"/>

 

 

if this does not work, then try to use 

 

<granite:rendercondition
         jcr:primaryType="nt:unstructured"
         sling:resourceType="/libs/granite/ui/components/coral/foundation/renderconditions/simple"
         expression="${granite:url(paramValues["item"][0]) == "/content/abc/us/en" || granite:url(paramValues["item"][0]) == "/content/abc/us/fr"  || granite:url(paramValues["item"][0]) == "/content/abc/gb/en" }"/>

 

 

https://developer.adobe.com/experience-manager/reference-materials/6-5/granite-ui/api/jcr_root/libs/... 

 

or you can create your own custom rendercondition 

https://medium.com/@arunpatidar26/custom-render-conditions-in-aem-392cae88a800 



Arun Patidar