AEM Granite Render Conditions

Photo by Muesli on Unsplash

A Granite Render Condition is a way of conditionally rendering a component in an AEM Touch UI dialog.

There are many situation where you might want to conditionally display an element of a dialog. Some examples are:

  • Displaying a field depending on the user group
  • Displaying a field depending on the page path
  • Displaying a field if the page is active

Out of the Box Render Conditions

AEM provides several OOTB render conditions that might be enough for your needs where the (probably) most used is the Simple render condition /libs/granite/ui/components/coral/foundation/renderconditions/simple

Using Simple Render Condition

<?xml version="1.0" encoding="UTF-8"?>
      expression="${granite:containsIgnoreCase(requestPathInfo.suffix, '/foo/bar')}"/>

In the example above the text field will only show if your url suffix ends in /foo/bar. e.g. http://localhost:4502/content/mysite/mypage.html/foo/bar

Custom Render Condition

Let’s create an example where you want to provide a list of user groups that can see/edit the field.

The examples in AEM use JSPs, however my recommendation is not to use JSPs as there are many disadvantages in the long run.

OOTB render conditions
OOTB render conditions

First let’s create a Sling Model.

@Model(adaptables = SlingHttpServletRequest.class)
public class UserGroupRenderCondition {

    private SlingHttpServletRequest request;

    private ResourceResolver resourceResolver;

    private String groups;

    public void init() {
        List<String> allowedGroups = Arrays.asList(groups.split(","));
        UserManager userManager = resourceResolver.adaptTo(UserManager.class);
        if (userManager == null) {
        boolean belongsToGroup = false;
        try {
            Authorizable currentUser = userManager.getAuthorizable(resourceResolver.getUserID());
            Iterator<Group> groupsIt = currentUser.memberOf();
            while (groupsIt.hasNext()) {
                Group group =;
                String groupId = group.getID();
                if ( -> g.equals(groupId))) {
                    belongsToGroup = true;
        } catch (RepositoryException e) {
            //LOG error
            new SimpleRenderCondition(belongsToGroup));

Now , let’s call the model in the HTL.

Create the following structure:

          /renderconditions (nt:folder)
                         /user-group (nt:folder)
                                 /user-group.html (nt:file) 

Then update user-group.html

<sly data-sly-use="com.mycompany.mysite.rendercontions.models.UserGroupRenderCondition"></sly>

Finally, update the render condition on your dialog:


You’ll see that the textfield only appears if you’re an admin or part of the Authors group.

Hope this was helpful. Get in touch on LinkedIn or leave comments for any questions or suggestions.

Leave a Reply