Involver Developer Network : partial
This page last changed on Apr 16, 2012 by david.tian@involver.com.
OverviewThe partial tag allows you to breakup small blocks of SML code into reusable templates. Caching ConsiderationsThis helper block has no caching considerations. Attributes
ExamplesSimple ExampleA 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 ExamplePartial blocks can be passed parameters by simply declaring additional attributes on 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 {% rss_feed name:'feed1' %} {% render partial:'my_partial' feed: rss_feed %} {% endrss_feed %} {% partial name:'my_partial' %} <!-- render logic --> {% endpartial %} AJAXing PartialsPartials 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 ExampleThis 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> FAQThis helper block currently has no FAQ questions. Related Topics |
![]() |
Document generated by Confluence on Feb 12, 2013 09:09 |