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

SOLVED

Conditionally Change Teaser Action URL

BrianBril
Level 1
Level 1

What are the recommendations/best practices for conditionally modifying links of actions from the Teaser component based on various business rules.

 

Environment:

- AEM 6.5.8

- Core Components 2.14.0

 

Use Case:

Authors add the Teaser component to a page. While doing so, they enable and add actions to the Teaser component.

 

When the page is rendered, we would like to add a query string to the URL associated with the action based on conditions defined by business rules. So, for certain links, we would like them to appear as https://ourcompany.com/products/ourproduct1.html?param1=1234&param2=abcd, but, for others it would simply appear as https://ourcompany.com/products/ourproduct2.html.

 

We have tried both front-end and backend solutions.

 

On the front-end, we have tried to overlay the action.html file to pass the ${action.URL} parameter to javascript in order to take the original value entered by the author and modify it per requirements. However, it seems as we are unable to pass that value into javascript as they are coming across as undefined.

 

In the back-end, we have tried to access the actions, but, Teaser actions are of type List<ListItem> which is an unmodifiable collection. As a result, we are not able to modify action elements.

 

Question:

Is there a best practice or preferred manner in which we can accomplish the above?

1 Accepted Solution
Arun_Patidar
Correct answer by
Community Advisor
Community Advisor

Hi,

You can extend the teaser and modify the links

https://github.com/arunpatidar02/aem63app-repo/blob/master/java/CustomTeaser.java

 

1. get a link from teaser.getActions(); inside init and create a new list out of it

2. return new list 

@Override
	public List<ListItem> getActions() {
		return newActionList;
	}

View solution in original post

1 Reply
Arun_Patidar
Correct answer by
Community Advisor
Community Advisor

Hi,

You can extend the teaser and modify the links

https://github.com/arunpatidar02/aem63app-repo/blob/master/java/CustomTeaser.java

 

1. get a link from teaser.getActions(); inside init and create a new list out of it

2. return new list 

@Override
	public List<ListItem> getActions() {
		return newActionList;
	}

View solution in original post