1

Is it possible to change the component that has to be rendered as a component presentation in java dxa 1.2. For example, if an Article component with id tcm:5-100 is inserted on the page with Article CT.

During the component presentations rendering in delivery, can I replace the existing component with a different Article component with id tcm:5-101 which I have fetched through broker API based on particular metadata field value.

If it is possible please guide me with the method that has to be extended/ modified if required.

  • @Bart pointed out you could get (Dynamic) Component Presentations using DD4T calls/methods in a DXA setup. Would this work for you? – Alvin Reyes Apr 5 at 15:46
  • Thanks Alvin, this article helped me to understand about dd4t api method used to retrieve the component presentation but how can I add this back to the page in place of existing component presentation? – user3113876 Apr 5 at 17:20
  • Can you elaborate on why you want to do this? – Rick Pannekoek Apr 5 at 20:05
  • @Rick, I am looking for this because I want to display user specific article based on a value received from third party service. The value which is received for a user is stored during content creation in article components. I will fetch this matched article component through broker api and I want to display this in place of default article which is inserted on page. – user3113876 Apr 6 at 3:15
  • 1
    Yes Alvin. You are right it is personalized content for users. But I am not hardcoding tcm uri, I am fetching tcm uri through broker api based on a value which is received from third party service. – user3113876 Apr 7 at 3:16
2

Like Alvin already mentioned, your requirements sound quite similar to what Experience Optimization does; you may want to take a look at the XO/SmartTarget Module to see how this kind of functionality is implemented there.

Spoiler: the XO/SmartTarget Module leverages the concept of Regions and can dynamically populate "SmartTarget Regions" with the results from an XO Query; if the query yields no results, it will keep fallback content coming from CM (if any). Technically speaking, the XO/SmartTarget Module uses a so-called Page Model Builder to dynamically inject Entity Models in the SmartTarget Region Models.

Another common way to dynamically modify View Models is using a custom Entity Controller. You already mentioned you have a Component Presentation (Entity Model in DXA speak) which represents a placeholder to be personalized. With a custom Entity Controller, you can dynamically post-process this Entity Model (if needed, it can even completely replace the Entity Model with another, based on a dynamic query).

Several DXA Modules have custom Entity Controllers. For example, the Search Module has a SearchController.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.