Syntax for module's named parameters - need your feedback
Lucian Cozma Oct 13, 2014 8:10 AMHi all.
We would like to make an improvement on the liquid’s syntax for the module’s named parameters and we need some input from you. We talked with a few of you “live” at Adobe MAX about this, and we would appreciate some input from more of you.
How to specify if the module’s output is suppressed or not?
Current syntax is, for the module_webapps for example:
{module_webapps id="stores" filter="all" template=""}
Basically, specifying an empty template will suppress the output of the module and will capture the module’s data in a variable who’s name it’s auto-generate. For example, creating a page with the following code will suppress the output of the module and generate a variable in the page called “webapps_0” what contains all the data generated by the webapps module (you will see this information in the “this” variable outputted as JSON).
<!DOCTYPE html>
<html>
<head>
<title>Untitled page</title>
<meta name="description" content="" />
</head>
<body>
{module_webapps id="stores" filter="all" template=""}
{{this|json}}
</body>
</html>
This syntax can be confusing, so we would like to change this into:
{module_webapps id="stores" filter="all" render=”nothing”}
Basically, add a render=”nothing” parameter that, if specified, will suppress the output of the module.
How to specify the variable in which a module data is captured?
For the above example, if we would like that the data is not captured in a automatically-generated variable, currently you have to do it like this, using the “collection” parameter.
{module_webapps id="stores" filter="all" template="" collection=”myStoresVar”}
{{myStoresVar |json}}
This can also be somewhat confusing, so we would like to replace with:
{module_webapps id="stores" filter="all" render=”nothing” var=”myStoresVar”}
How to specify how to render a module that renders a list of data?
Currently the template you specify to the webapp module specifies how to render a single-item of data. So if I had a module in a page like this:
{module_webapps id="stores" filter="all" template="/before-after/item.tpl"}
And the item.tpl would be:
<div>
<h1>{{name}}</h1>
<div>{{description}}</div>
</div>
The item.tpl would contain the template of a single item and the module would loop through every record resulting in an output like:
<div>
<h1>Starbucks #240</h1>
<div><p>Starbucks - 505 S Flower St Los Angeles, CA 90071</p></div>
</div>
<div>
<h1>Starbucks #308</h1>
<div><p>Starbucks - 735 S Figueroa St #308 Los Angeles, CA, 90017</p></div>
</div>
But if you want to be able to control in the template the layout of all of the things the module outputs (and get control of the loop), you currently have to do things like this:
{module_webapps id="stores" filter="all" template="/before-after/list.tpl"}
And in the list.tpl:
<!-- Liquid Enable Collection -->
{% for item in items %}
<div>
<h1>{{item.name}}</h1>
<div>{{item.description}}</div>
</div>
{% endfor %}
Notice that comment at the beginning of the template. That instructs BC that the template is not for a single item, but for the entire list, and so you get access to the ”items” of the collection so that you can control the loop yourself.
The usage of the comment can also be confusing and more difficult to understand so we would propose not to use a comment in a template but use the same render=”” parameter, but with another value:
{module_webapps id="stores" filter="all" render=”collection” template="/before-after/list.tpl"}
And remove the comment from list.tpl:
{% for item in items %}
<div>
<h1>{{item.name}}</h1>
<div>{{item.description}}</div>
</div>
{% endfor %}
What do you guys think?
In this way we would have a consistent and simple way to define how a module is being rendered and how:
{module_webapps id="stores" filter="all" render=”collection” template="/before-after/list.tpl”} to get access in the module to the entire collection to loop through the items ourselves or
{module_webapps id="stores" filter="all" render=”item” template="/before-after/item.tpl”} to define only how every item looks and have the module loop for me (render=”item” would be by default to insure backwards compatibility, and in the template I am able to access the values directly).
Any thoughts on this?
-Lucian




