This page last changed on Apr 16, 2012 by david.tian@involver.com.

Overview

The partial tag allows you to breakup small blocks of SML code into reusable templates.


Caching Considerations

This helper block has no caching considerations.


Attributes

name type required description
name string false This is the unique name the SML will use to look up which partial to render. Note: underscores are the only special character allowed in a partial name

Examples

Simple Example

A basic partial block that displays the coupon feature block.

{% partial name:'free_pizza_coupon'%}
  {% coupon %}{% endcoupon %}
{% endpartial %}

Then to render the partial

{% render partial:'free_pizza_coupon' %}

Complex Example

Partial blocks can be passed parameters by simply declaring additional attributes on the render tag.
Within the partial, the passed parameters can be referenced by their attribute names. Partials can only
reference variables that are explicitly passed using the render tag.

In this example we are rendering two rss feeds using the same partial template.

{% partial name: 'feed_partial' %}
     {% for item in feed.feed_items %}
          {{ item.title }}
     {% endfor %}
{% endpartial %}

{% rss_feed name:'feed1' %}
     {% render partial:'feed_partial' feed: rss_feed %}
{% endrss_feed %}

{% rss_feed name:'feed2' %}
     {% render partial:'feed_partial' feed: rss_feed %}
{% endrss_feed %}

Partials MUST be declared before than can be used with the render tag. For example, the following code
will fail because my_partial is declared after it is used:

{% rss_feed name:'feed1' %}
     {% render partial:'my_partial' feed: rss_feed %}
{% endrss_feed %}

{% partial name:'my_partial' %}
     <!-- render logic -->
{% endpartial %}

AJAXing Partials

Partials can be deferred from rendering on page load by using the ajax_link tag. This tag generates a link that, when clicked, will load a given partial, render it and insert the output into a given html node. This can be a useful when optimizing the initial page load time when certain sections of the page are initially hidden from the user (as in a tab panel or dialog, for example).


AJAX Example

This example loads a partial using ajax only if a user clicks on the given ajax_link.

{% partial name:'lazy_partial' %}
  {% rss_feed %}
    {% paginate rss_feed.feed_items per_page:5 %}
       {% for item in feed_items %}
        {{item.title}}<br>
       {% endfor %}
    {% endpaginate %}
  {% endrss_feed %}
{% endpartial %}

<!-- this generates a link that will load the rss feed represented in the above partial -->
{% ajax_link partial:'lazy_partial' container:'rss_container' %}load rss feed{% endajax_link %}

<div id="rss_container">
  <!-- this container will be populated with the rss feed -->
</div>

FAQ

This helper block currently has no FAQ questions.


Related Topics

Document generated by Confluence on Feb 12, 2013 09:09