Show a tab in page properties only if page is under /content/A and /content/B in the content tree | Community
Skip to main content
Level 6
July 4, 2023
Solved

Show a tab in page properties only if page is under /content/A and /content/B in the content tree

  • July 4, 2023
  • 4 replies
  • 2343 views

I have a tab in the page template. It shows in page properties for all pages. 

I would like to restrict it only for pages under /content/A and /content/B in the content tree.

I tried solving this using <granite:rendercondition condition="${condition}"> but it didn't work. How can I use granite:condition to show a Tab only for specific PATHS?

Any suggestions how to approach this task?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by imshailesh

Hi @anasustic !

Can you please confirm while opening page properties of a page, you are getting encoded URL (http://localhost:4506/mnt/overlay/wcm/core/content/sites/properties.html?item=%2Fcontent%2Fzkb%2Fde%2Fprivate%2Fdetail), as when I am trying to open page properties of any page it is coming like https://localhost:4502/mnt/overlay/wcm/core/content/sites/properties.html?item=/content/we-retail/us/en/experience/arctic-surfing-in-lofoten.

Also, I am able to hide a tab using below render condition properties,



param.item will get you /content/we-retail/us/en/experience/arctic-surfing-in-lofoten.

For debugging, you can use

 

<%@ page import="org.apache.commons.logging.Log" %> <%@ page import="org.apache.commons.logging.LogFactory" %>

 

 

and logging statement as 

 

 

Log logger = LogFactory.getLog( this.getClass( ) ); String suffix = slingRequest.getParameter("item"); logger.info( "This is a suffix" + suffix);

 

 You can see the logs in error.log of aem instance. 

Below is my /libs/granite/ui/components/coral/foundation/renderconditions/simple/simple.jsp

 

<%@ include file="/libs/granite/ui/global.jsp" %><% %><%@ page session="false" import="com.adobe.granite.ui.components.Config, com.adobe.granite.ui.components.rendercondition.RenderCondition, com.adobe.granite.ui.components.rendercondition.SimpleRenderCondition" %> <%@ page import="org.apache.commons.logging.Log" %> <%@ page import="org.apache.commons.logging.LogFactory" %> <%--### Simple ====== .. granite:servercomponent:: /libs/granite/ui/components/coral/foundation/renderconditions/simple :rendercondition: A condition that takes a simple boolean for the decision. It has the following content structure: .. gnd:gnd:: [granite:RenderConditionsSimple] /** * The expression to evaluate. */ - expression (BooleanEL) = true ###--%><% Log logger = LogFactory.getLog( this.getClass( ) ); Config cfg = cmp.getConfig(); String suffix = slingRequest.getParameter("item"); logger.info( "This is a suffix" + suffix); boolean vote = cmp.getExpressionHelper().getBoolean(cfg.get("expression", "true")); request.setAttribute(RenderCondition.class.getName(), new SimpleRenderCondition(vote)); %>

 


Note : This functionality will not work for tab when we are trying to create a page due to issue I mentioned in last reply.

4 replies

EstebanBustamante
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
July 4, 2023

Here you have a list of possible examples ootb, https://gist.github.com/nateyolles/eec2f56acc7153fe9fb7dd6637e8f7ad you can check if this works:

<granite:rendercondition jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/renderconditions/simple" expression="${granite:containsIgnoreCase(requestPathInfo.suffix, '/foo/bar')}"/>

If none of the above works, you can simple add a custom one which will check the tree path, refer to this if you don't know how to add a custom one:
https://jpsoares.medium.com/aem-granite-render-conditions-438c804b1e5a 

Esteban Bustamante
aanchal-sikka
Community Advisor
Community Advisor
July 4, 2023
anasusticAuthor
Level 6
July 5, 2023

Hi @aanchal-sikka thanks for your reply. We are not using acs-commons.

DPrakashRaj
Community Advisor
Community Advisor
July 5, 2023
Level 2
July 5, 2023

Hello everyone !

 

There is some catch when we are trying to use Simple Render Condition while hiding/showing any tab during page creation. Below are my findings:

${granite:containsIgnoreCase(requestPathInfo.suffix, '/content/we-retail')} is giving false for the below url http://localhost:5502/mnt/overlay/wcm/core/content/sites/createpagewizard.html/content/we-retail/us/en/experience

 

When I debugged more, what value is being returned for slingRequest.getRequestPathInfo().getSuffix() in /libs/granite/ui/components/coral/foundation/renderconditions/simple/simple.jsp, I could see it is returning /conf/we-retail/settings/wcm/templates/content-page. I am still trying to figure out why it is returning template path instead of page path where we are trying to create page. 

Any leads for this will be useful.

Regards,
Shailesh 

anasusticAuthor
Level 6
July 6, 2023

Hi @imshailesh 
That is super interesting. Thanks for sharing.
How were you able to debug /libs/granite/ui/components/coral/foundation/renderconditions/simple/simple.jsp?

This is my URL http://localhost:4506/mnt/overlay/wcm/core/content/sites/properties.html?item=%2Fcontent%2Fxxx%2Fen%2Fprivate%2Fdetail
and in my case the following rendercondition also does not return true therefore hiding the tab for pages under /content/xxx


<granite:rendercondition
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/renderconditions/simple"
expression="${granite:containsIgnoreCase(requestPathInfo.suffix, '/content/xxx')}"/>

 

imshaileshAccepted solution
Level 2
July 6, 2023

Hi @anasustic !

Can you please confirm while opening page properties of a page, you are getting encoded URL (http://localhost:4506/mnt/overlay/wcm/core/content/sites/properties.html?item=%2Fcontent%2Fzkb%2Fde%2Fprivate%2Fdetail), as when I am trying to open page properties of any page it is coming like https://localhost:4502/mnt/overlay/wcm/core/content/sites/properties.html?item=/content/we-retail/us/en/experience/arctic-surfing-in-lofoten.

Also, I am able to hide a tab using below render condition properties,



param.item will get you /content/we-retail/us/en/experience/arctic-surfing-in-lofoten.

For debugging, you can use

 

<%@ page import="org.apache.commons.logging.Log" %> <%@ page import="org.apache.commons.logging.LogFactory" %>

 

 

and logging statement as 

 

 

Log logger = LogFactory.getLog( this.getClass( ) ); String suffix = slingRequest.getParameter("item"); logger.info( "This is a suffix" + suffix);

 

 You can see the logs in error.log of aem instance. 

Below is my /libs/granite/ui/components/coral/foundation/renderconditions/simple/simple.jsp

 

<%@ include file="/libs/granite/ui/global.jsp" %><% %><%@ page session="false" import="com.adobe.granite.ui.components.Config, com.adobe.granite.ui.components.rendercondition.RenderCondition, com.adobe.granite.ui.components.rendercondition.SimpleRenderCondition" %> <%@ page import="org.apache.commons.logging.Log" %> <%@ page import="org.apache.commons.logging.LogFactory" %> <%--### Simple ====== .. granite:servercomponent:: /libs/granite/ui/components/coral/foundation/renderconditions/simple :rendercondition: A condition that takes a simple boolean for the decision. It has the following content structure: .. gnd:gnd:: [granite:RenderConditionsSimple] /** * The expression to evaluate. */ - expression (BooleanEL) = true ###--%><% Log logger = LogFactory.getLog( this.getClass( ) ); Config cfg = cmp.getConfig(); String suffix = slingRequest.getParameter("item"); logger.info( "This is a suffix" + suffix); boolean vote = cmp.getExpressionHelper().getBoolean(cfg.get("expression", "true")); request.setAttribute(RenderCondition.class.getName(), new SimpleRenderCondition(vote)); %>

 


Note : This functionality will not work for tab when we are trying to create a page due to issue I mentioned in last reply.