demandwaresalesforce-commerce-cloud

Can I pass parameters to a content slot from the calling ISML?


I'd like to be able to pass some supplementary information to a Content Slot, either through a request scope variable or some other means.

I've tried this in my calling ISML:

<isset name="message" scope="request" value="I want to be an Air Force Ranger" />
<isslot id="slot-message" context="global" description="banner"/>

And in the rendering template for the slot I have:

<iscontent type="text/html" charset="UTF-8" compact="true"/>
<iscache type="relative" hour="24"/>
<h3>${request.custom.message}</h3>

However, in the output HTML, I just get:

<h3>null</h3>

Is there some way I can pass an Object or String to a Content Slot?


Solution

  • Content asset don't have access to the data created or passed to ISML. However, a workaround can be done by adding the data to the DOM and then reading it inside the content asset:

    <div class="banner-data" data-message="${message}">
        <isslot id="slot-message" context="global" description="banner"/>
    </div>
    

    Then, in your content asset, you can read the message and use it:

    <script>
        var bannerData = $('.banner-data').data();
        var message = bannerData["message"];
    </script>