Expand my Community achievements bar.

SOLVED

how to check content in rendercondition

Avatar

Level 2

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

1 Accepted Solution

Avatar

Correct answer by
Level 2

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)

Maikman831_0-1682498275083.png

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

View solution in original post

4 Replies

Avatar

Community Advisor

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

Avatar

Level 2

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

Avatar

Community Advisor

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

Avatar

Correct answer by
Level 2

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)

Maikman831_0-1682498275083.png

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