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?
Solved! Go to Solution.
Views
Replies
Total Likes
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%... 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....
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.
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
Hello @anasustic
If you are using ACS Commons, please refer to https://adobe-consulting-services.github.io/acs-aem-commons/features/ui-widgets/path-rendercondition...
Hi @aanchal-sikka thanks for your reply. We are not using acs-commons.
Take a look at this thread on which similar task was asked https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/displaying-a-dialog-fields...
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
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%...
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')}"/>
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%... 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....
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.
Thank you very much @imshailesh for taking the time to answer my question.
Yes, it works nicely like described in your post and I was able to log it in error.log by altering simple.jsp.
<granite:rendercondition
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/renderconditions/simple"
expression="${!granite:containsIgnoreCase(param.item, '/content/xxx')}"/>
I was able to reproduce your issue by creating the new page.
While creating the page the suffix appears to be null:
07.07.2023 14:15:31.977 *INFO* [[0:0:0:0:0:0:0:1] [1688732131969] GET /mnt/overlay/wcm/core/content/sites/createpagewizard/properties.html/conf/xxx/settings/wcm/templates/landingpage HTTP/1.1] org.apache.jsp.libs.granite.ui.components.coral.foundation.renderconditions.simple.simple_jsp This is a suffix null
Views
Likes
Replies