Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list

Show/Hide Page Properties Based on Template in AEM | AEM Community Blog Seeding




Show/Hide Page Properties Based on Template in AEM by Bimmisoi


In AEM , editable templates usually share the same page component, which means the same page properties dialog.
Below are the steps to show/hide page properties based on the template.

1. Create a jsp under apps “/apps/project-name/granite/rendercondition/template/template.jsp” with below code.

<%@include file="/libs/foundation/global.jsp"%>
<%@page session="false"

final ComponentHelper cmp = new ComponentHelper(pageContext);
Config cfg = cmp.getConfig();
String path = cfg.get("templatePath", "");
boolean vote = TemplateRenderConditionUtil.isTemplate(slingRequest, request, path);
request.setAttribute(RenderCondition.class.getName(), new SimpleRenderCondition(vote));

2. Now create a java file named TemplateRenderConditionUtil with below code as you can see we have used this java class in the jsp code.

import java.util.Optional;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
public class TemplateRenderConditionUtil {
private static final String PAGE_PROPERTIES = "wcm/core/content/sites/properties";
public static boolean isTemplate(
SlingHttpServletRequest slingHttpServletRequest,
HttpServletRequest httpServletRequest,
String templatePath) {
// error if any of the passed params is null.
if (slingHttpServletRequest == null || httpServletRequest == null
|| StringUtils.isBlank(templatePath)) {
throw new IllegalArgumentException("One of the passed parameters is null.");
// the dialog is a page properties dialog
if (StringUtils.contains(httpServletRequest.getPathInfo(), PAGE_PROPERTIES)) {
// get the actual page path
String pagePath = httpServletRequest.getParameter("item");
// get page template path and check it
return Optional.ofNullable(slingHttpServletRequest.getResourceResolver())
.map(resourceResolver -> resourceResolver.getResource(pagePath))
.map(pageResource -> pageResource.adaptTo(Page.class))
.map(path -> StringUtils.contains(path, templatePath))
return false;

Read Full Blog

Show/Hide Page Properties Based on Template in AEM


Please use this thread to ask the related questions.


Topics help categorize Community content and increase your ability to discover relevant content.

1 Reply


Level 5

Hi @kautuk_sahni ,


Thank you for this post.


My Question:


Is there any possibilty to provide mutiple template paths for “templatePath”. I want to achieve same feature for more than 1 template. Thank you in advance.