This page last changed on May 25, 2011 by moses.lee@involver.com.

sml.tag.Partial

Allows for programmatic rendering of partials via AJAX


Class Methods

.get()

Gets the partial object

Example

{% partial name:'my_partial' %}
This is a partial!
{% endpartial %}


<script>
var partial_object = sml.tag.Partial.get('my_partial');
</script>

Instance Methods

.render()

Renders the partial server-side for the partial object this method is called on. Returns the rendered partial HTML in the success callback.

Params

name type description
locals object An associative array or JSON hash of variables that you want available for rendering in the partial
success function Callback function that receives the rendered partial HTML
error function Callback function that is executed upon server-side rendering error (optional)
scope object Variable scope of the success/error callback functions (optional)

Example

Renders the partial with local variables:
{% partial name:'my_partial' %}
Value of local variable 'foo': {{ foo }}
{% endpartial %}

<div id="my_partial_container"></div>

<a href="#" onclick="renderMyPartial(); return false;">Render My Partial</a>

<script>
function renderMyPartial() {
  sml.tag.Partial.get('my_partial').render({
    locals: {foo: 'I am foo!'},
    success: function(html) {
      jQuery('#my_partial_container').html(html);
    },
    error: function() {
      sml.log('Render Failed!');
    }
  });
}
</script>
Render a partial that is passed an SML variable via the 'serialize' filter:
{% rss_feed %}

  {% partial name:'my_partial' %}
    Number of RSS feed items: {{ rss_feed.feed_items.size }}
  {% endpartial %}

  <a href="#" onclick="renderMyPartial(); return false;">Render My Partial</a>

  <div id="my_partial_container"></div>

  <script>
  function renderMyPartial() {
    sml.tag.Partial.get('my_partial').render({
      locals: {rss_feed: {{rss_feed | serialize}}}, // Serializes rss_feed to JSON that the partial renderer understands
      success: function(html) {
        jQuery('#my_partial_container').html(html);
      },
      error: function() {
        sml.log('Render Failed!');
      }
    });
  }
  </script>
{% endrss_feed %}

Related Topics

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