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

2.5k views Asked by At

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?

2

There are 2 answers

1
Sam Gh On BEST ANSWER

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>
0
Jesper On

Content Assets is not aware of the page they are embedded in. This is by design. You can however embed HTML inside your content by using $include()$ which fetches html from a named controller or link to another page on the site using any of the $url-methods.

In the Content Templates it is further possible to reference data from the contentslot or from the content itself using: ${slotcontent} and ${slotcontent.content} respectively.