how to check content in rendercondition | Community
Skip to main content
Level 2
April 26, 2023
Solved

how to check content in rendercondition

  • April 26, 2023
  • 2 replies
  • 1551 views

Hi people,

 

I like to create a custom rendercondition for a component dialog, that looks into the content of the actuall instance of the dialog (so what is put into /content inside the DAM) and check for a certain constellation.

 

Problem so far: the rendercondition is not aware of the resource I am working on. It looks like the condition only sees itself and has no information about the component I actually editing.

 

Some technical information:

The rendercondition is somewhere here: /apps/myApp/renderconditions/myRendercondition/myRendercondition.jsp

It is referenced in a component here: /apps/myApp/myComponents/myFancyComponent/cq:dialog/myItem/granite:rendercondition/myRendercondition

 

And this is basically working. So if I return true or false, myItem is shown or not.

But the rendercondition need to check data that is here: /content/mySite/myFancyComponent_1/data

I tried a lot of things but I don't found a way, the rendercondition finds out where the content is that is actually edited.

 

Anyone any idea? Is this even possible?

Best, Maik

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 Maikman831

Hi @arunpatidar,

interesting, too, but again a very global sight from above. I will keep that in mind for future needs.

 

What me helped now: http://www.nateyolles.com/blog/2016/07/aem-granite-custom-render-conditions

I checked the GitHub sources behind it and found the solution. I need to put this when configuring the rendercondition:

resourcePath - $(requestPathInfo.suffix)

In my jsp I can access the resourcePath via this way:

ExpressionHelper expressionHelper = new ExpressionHelper(sling.getService(ExpressionResolver.class), pageContext);
Config cfg = new Config(resource);
String resourcePath = expressionHelper.getString(cfg.get("resourcePath", String.class));

 

And now I have the resourcePath I was looking for. With the resolver I can get the resource behind the path and can do whatever I want to do.

 

Thanks for your time,

Maik

2 replies

arunpatidar
Community Advisor
Community Advisor
April 26, 2023

Please try to run in debug mode or write debugger to check where it is failing.

Below is the example of renderer condition using servlet which easy to implement/and debug than a jsp

http://aemlab.blogspot.com/2019/07/aem-granite-custom-render-conditions.html 

Arun Patidar
Level 2
April 26, 2023

Hi @arunpatidar,

thank you for the response and the interesting link.

But there is no failure, so there is nothing to debug and to check.

 

And I think you might missed my point. Your example and all the others I found refer to conditions, that check propertys of the component definition (so everything under /apps). But this is not what I need.

What I need:

Put the component on a page, click the edit button for the component to get into the edit dialog, let the rendercondition run and check data behind the component (let's say something like the author set the title to "big news" and I want to react on "title is set to "big news"").

 

Best, Maik

arunpatidar
Community Advisor
Community Advisor
April 26, 2023

Hi @maikman831 

It is possible to check condition in /content are as well. It is upto you what you write as a Business logic.

Let me share one more intresting link if that helps : https://aemlab.blogspot.com/2018/06/sling-feature-flag.html  

Arun Patidar
Maikman831AuthorAccepted solution
Level 2
April 26, 2023

Hi @arunpatidar,

interesting, too, but again a very global sight from above. I will keep that in mind for future needs.

 

What me helped now: http://www.nateyolles.com/blog/2016/07/aem-granite-custom-render-conditions

I checked the GitHub sources behind it and found the solution. I need to put this when configuring the rendercondition:

resourcePath - $(requestPathInfo.suffix)

In my jsp I can access the resourcePath via this way:

ExpressionHelper expressionHelper = new ExpressionHelper(sling.getService(ExpressionResolver.class), pageContext);
Config cfg = new Config(resource);
String resourcePath = expressionHelper.getString(cfg.get("resourcePath", String.class));

 

And now I have the resourcePath I was looking for. With the resolver I can get the resource behind the path and can do whatever I want to do.

 

Thanks for your time,

Maik