Skip to content

A underscore mixin that allows you to define global helpers for the underscore.js template function.

License

Notifications You must be signed in to change notification settings

dgbeck/underscore-template-helpers

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

Define global template helpers in underscore. Example:

_.addTemplateHelpers( {
	iff : function( condition, outputString ) {
		return condition ? outputString : "";
	}
} );

Now in an underscore template:

<script type="text/template">
	<div class="button <%= iff( isHightlighted, "highlighted" ) %>">
		My button
	</div>
</script>

Using with Backbone.Subviews

This mixin comes in handy when used with the Backbone.Subviews View mixin to insert subviews into a view template:

_.addTemplateHelpers( {
	subview : function( subviewName ) {
		return "<div data-subview='" + subviewName + "'></div>"
	}
} );

Now to create a subview from your template, you just need:

<script type='text/template' id="MyItemViewTemplate">
	<h1>This is my item view template</h1>

	<%= subview( "mySubview" ) %>
</script>

About

A underscore mixin that allows you to define global helpers for the underscore.js template function.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published