Passing custom parameters to modules

Updated on 20-October-2016 at 10:16 AM

Business Catalyst End of life announcement - find out more details.

Do note this technique only applies to modules which use the named parameters syntax.

Traditionally each layout has a set of tags it can use. That also applies to Liquid, on any given layout you can access a limited set of layouts.

You can however, extend the amount of informaiton available in a layout by passing additional parameters to the module itself.

For example,

  • I have the {module_productfeaturelist} module inserted on a page like so:

  {module_productfeaturelist tag="featured" collection="product-tag" skyColor="The sky is blue." visitorDeviceType="{{this.globals.visitor.deviceClass}}" currentPageName="{module_pagename}"}
  • this module will be rendered using the default Individual Product - Small layout . By passing the custom parameters param1, param2 and param3 I make "The sky is blue" string, the type of device and the name of the page available on the product list layout
  • on the Individual Product - Small layout we can use these Liquid tags:
    • {{params.</span>skyColor}} - outputs "The sky is blue."
    • {{params.visitorDeviceType}} - outputs "desktop", "tablet" or "phone"
    • {{params.currentPageName}} - outputs the current page name

Note: The parameter names are not fixed, you can name them anything you want. When getting their value always use params. before the parameter's name.

Let's build a setup to further demonstrate this feature. On the blog post details layout insert the webapps module at the very end:

{module_webapps render="collection" customparam="{{author}}" template="/layouts/custom/car_collection_blog.tpl" id="35209" filter="all"}

By adding the customparam parameter to the module syntax we are basically injecting its value - the blog post's author name make this piece of information available for later use on the webapp list layout where we can use it in the Liquid logic.

Now let's edit the /layouts/custom/car_collection_blog.tpl layout and make use of the blog post's author name:

<table>
    <thead>
        <th>Make</th>
        <th>Engine size (L)</th>
        <th>Engine layout</th>
        <th>Performance</th>
    </thead>
    <tbody>
				{% for item in items %} 
				{% unless {{item.['engine layout']}} contains contains this.params.customparam %}
        <tr>
            <td>{{item.name}}</td>
            <td>{{item.['engine size']}}</td>
            <td>{{item.['engine layout']}}</td>
            <td>{{item.performance}}</td>
        </tr>
				{%endunless%} 
			    {%endfor%}
	</tbody>
</table>

When we open up a blog post, module_webapps will be passed its author and will be rendered based on our custom logic. In this example only the webapp items whose "owner" fields contain the name of the blog post author will be shown.