Developer forum

Forum » Rapido » Rapido - Change template for ProductContainer

Rapido - Change template for ProductContainer

Aki Ruuskanen
Aki Ruuskanen
Reply

Hi,

I'm trying get different templates to load for the ProductsContainer depending on some conditions on page load. 

Example:

If a condition is true I want the ProductsContainer to be loaded with "ProductGridItemContainer" otherwise with "ProductDetailsItemContainer".

 

I have tried to just set the "data-template" with a razor variable to for example "ProductGridItemContainer". That sets the "data-template" correctly but the items are still like it would be set to  "ProductDetailsItemContainer" (if that was the previous state).

I guess I need to call "Dynamo.UpdateTemplate('ProductsContainer', 'ProductItemContainer')" at some appropriate point. 

I obviously cannot do that in "DOMContentLoaded". Is there a way to know when Dynamo has finished rendering the template?

Regards / Aki

 


Replies

 
Karsten Thuen Dynamicweb Employee
Karsten Thuen
Reply
This post has been marked as an answer

Hi Aki

First off. The list view setting is saved in a cookie, and that overrules all other settings. That may be the reason you do not see the change. Have you made the conditional in the Json feed? 

If you want to not save the view setting in a cookie, start by removing "data-save-cookie="true"" from the ProductsContainer element in the ProductsRender.cshtml

Then in the JSON feed (Shown in the gif below), make a "template" property. Then you could fx. make a condition to check if the user is checked in, and the show one productlist for that user and another for users that is not signed in.

If you really need to use javascript, Dynamo throws an event on "contentLoaded".  You should be able to call it on:
 

document.getElementById("productList").addEventListener('contentLoaded', function (e) {

                //Do your stuff

}, false);

 

Best regards
Karsten Thuen

SwitchTemplate.gif
Votes for this answer: 1
 
Aki Ruuskanen
Aki Ruuskanen
Reply

Alright. Thanks for the input! 

/Aki

 
Aki Ruuskanen
Aki Ruuskanen
Reply

Hehe, I just needed to remove the "data-save-cookie="true"". I thought that setting it to "false" would be enough. :)

/Aki

 

You must be logged in to post in the forum