Skip to content

A templating plugin for jQuery. BETA. NO LONGER IN ACTIVE DEVELOPMENT OR MAINTENANCE. Issues remain open but are not being worked.

Notifications You must be signed in to change notification settings

skdream/jquery-tmpl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

73 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A jQuery templating plugin. Note: this plugin requires jquery version 1.4.2.


// Render one LI, filled with data, then append it into the UL

$.tmpl( "<li>${firstName}</li>", dataObject )
	.appendTo( "ul" );

<!-- Declare a template as a script block of type "text/x-jquery-tmpl" -->

<script id="sometmpl" type="text/x-jquery-tmpl">
	<li>${firstName}</li>
</script>

// Render the declared template as one LI appended to the target UL

$( "#sometmpl" )
	.tmpl( dataObject )
	.appendTo( "ul" );

// Render the declared template as multiple LIs appended to the target UL
// Provide a click event accessing the data

$( "#sometmpl" )
	.tmpl( arrayOfDataObjects )
	.appendTo( "ul" )
	.click( function() {
		alert( $.tmpl(this).data.firstName );
	});

// Store a string as a compiled template for later use
$.template( "myTmpl", "<span>${firstName}</span>" );

// Render stored template and insert after target. 
$.tmpl( "myTmpl", dataObject )
	.insertAfter( "#target" );

About

A templating plugin for jQuery. BETA. NO LONGER IN ACTIVE DEVELOPMENT OR MAINTENANCE. Issues remain open but are not being worked.

Resources

Stars

Watchers

Forks

Packages

No packages published