The "template" parameter

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

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

Custom templates

The template parameter is mainly used to specify the path to a custom template that will be used to render the module. For example, the webapp module below will use the custom template car_collection.tpl instead of the default Webapp List layout.

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

For a detailed overview of using custom templates to render a module's content take a look at the Custom templates (layouts) article.

Supress a module's output

With the introduction of the Liquid rendering engine and the concept of Liquid collections, the template parameter now serves a second purpose: it can be used to suppress a module's output altogether by passing a blank template path.

For example, the webapp listing below does not render anything:

{module_webapps collection="myWebapp" template="" id="35209" filter="all"}

Even though the module is now "silent" and does not output anything on the page, behind the scenes it creates the myWebapp collection. You can now use Liquid to render the collection data.

Custom template, collection or both?

For most situations, using the default layout or custom module templates (using the template=?/path-to-file.tpl? parameter) to display module data is good enough.

Traditionally module_shoppingcartsummary would output something like this:

<span id="catCartSummary" quote="False" vertical="False">
        <table cellspacing="0" class="cartSummaryTable"> <tbody> <tr>
        <td class="cartSummaryItem"> 1 item(s), Total: $123.00 <a class="cartSummaryLink"
        href="/OrderRetrievev2.aspx?CatalogueID=0">View Cart</a> </td> </tr>
        </tbody> </table> </span>

If we insert it on a page like so:

{module_shoppingcartsummary collection="Mycart" template="/layouts/custom/cart-summary.tpl"}

The module will be rendered using the cart-summary.tpl - nothing new here. Using the Mycart collection however we can do something (show a div for example) if a shopping cart condition is met:

  • the cart's total value is over a certain sum
  • there are more than X items added in the cart
  • a certain product has been added to the cart
  • the site's country code has a certain value

For a more detailed implementation of this type of setup pelase take a look at the How to section.