Template Options

Attribute Prefix

You can set a prefix to apply to all jmvc template attribute names. Where possible it is advised to avoid changing the default attribute names. This flexibility is provided so attribute naming conflicts with other libraries can be avoided if they arise.

For example to prefix with 'jmvc-'
$(function(){
  jmvc.template.setOptions({ attributePrefix : 'jmvc-' })
});

Your template would look like this
<ul jmvc-condition="this.items != null && this.items.length > 0">
  <li jmvc-repeat="items" jmvc-bind="_self"></li>
</ul>

Custom Attribute Names

You can set custom attribute names to use in your templates for the existing jmvc template attributes. Where possible it is advised to avoid changing the default attribute names. This flexibility is provided so attribute naming conflicts with other libraries can be avoided if they arise.

For example to rename condition, repeat and bind
$(function(){
  jmvc.template.setOptions({ attributeNames : {
    condition: 'my-condition-alternative',
    repeat: 'my-repeat-alternative',
    bind : 'my-bind-alternative'
  }});
});

Your template would look like this
<ul my-condition-alternative="this.items != null && this.items.length > 0">
  <li my-repeat-alternative="items" my-bind-alternative="_self"></li>
</ul>

Using an alternate template engine

You can configure jmvc to use an alternative template engine. This is a achieved by setting a new template function via the setOptions method. The function signature should take the following parameters
  1. template - the template text (i.e. the content of the template script tag)
  2. model - the model to apply the template to
  3. view - the jmvc view (may not be required in the third party template engine)

The jmvc attributes will not be supported if using a third party template engine. The build in template engine provides support for wiring up UI events to controller actions (e.g. using the action attribute). If you use an alternate template engine you will need to do this manually.

The following example shows how set underscore as the template engine.
$(function(){
  jmvc.template.setOptions({ templateFunction : function(template, model, view) {
    return _.template(template, model);
  }});
});


Last edited Jun 29, 2014 at 11:51 PM by dpembroke, version 7