Gathering detailed insights and metrics for @codevadmin/jquery-tmpl
Gathering detailed insights and metrics for @codevadmin/jquery-tmpl
Gathering detailed insights and metrics for @codevadmin/jquery-tmpl
Gathering detailed insights and metrics for @codevadmin/jquery-tmpl
tmpl
JavaScript micro templates.
@n8n_io/riot-tmpl
n8n fork of the riot template engine
jquery
JavaScript library for DOM operations
blueimp-tmpl
1KB lightweight, fast & powerful JavaScript templating engine with zero dependencies. Compatible with server-side environments like Node.js, module loaders like RequireJS, Browserify or webpack and all web browsers.
npm install @codevadmin/jquery-tmpl
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
149 Commits
1 Forks
1 Watching
3 Branches
13 Contributors
Updated on 23 Jul 2019
Minified
Minified + Gzipped
JavaScript (92.31%)
CSS (6.45%)
HTML (1.24%)
Cumulative downloads
Total Downloads
Last day
20%
30
Compared to previous day
Last week
5.6%
150
Compared to previous week
Last month
-9.6%
606
Compared to previous month
Last year
-18.7%
8,416
Compared to previous year
1
jQuery Templates is no longer in active development, and has been superseded by JsRender.
JsRender functionality is a superset of the jQuery Templates feature set, and brings many improvements. The template tag syntax is similar. Rendering and compiling performance of JsRender is considerably better than jQuery templates performance.
Note: This is the original official jQuery Templates plugin. The project was maintained by the jQuery team as an official jQuery plugin. Since the jQuery team has decided not to take this plugin past beta, it has been returned to the principal developer's GitHub account (Boris Moore). For more information on the history of jQuery Templates, and the roadmap going forward, see jQuery Templates and JsViews: The Roadmap
See vBeta1.0.0 tag for released beta version. Requires jQuery version 1.4.2.
jQuery templates contain markup with binding expressions ('Template tags'). Templates are applied to data objects or arrays, and rendered into the HTML DOM.
Note that documentation for the jQuery Templates plugin is no longer maintained on the jQuery documentation site.
An archive copy of the original documentation (previously at api.jquery.com/category/plugins/templates/) can be found here.
See also http://www.borismoore.com/2010/10/jquery-templates-is-now-official-jquery.html for more background.
Live versions of some of the demos from this repository can be found at http://borismoore.github.io/jquery-tmpl/demos/step-by-step.html.
The beta1 version of jQuery Templates is available on CDN at:
The following is a restoration of jQuery's official documentation on tmpl() as it was on 12/28/2012. jQuery is Copyright 2012, John Resig
Render the specified HTML content as a template, using the specified data. version added: 1.4.3 jQuery.tmpl( template [, data] [, options] )
template The HTML markup or text to use as a template.
data The data to render. This can be any JavaScript type, including Array or Object.
options An optional map of user-defined key-value pairs. Extends the tmplItem
data structure, available to the template during rendering.
This documentation topic concerns the jQuery Templates plugin (jquery-tmpl), which can be downloaded from: http://github.com/jquery/jquery-tmpl.
The jQuery.tmpl()
method is designed for chaining with .appendTo
, .prependTo
, .insertAfter
or .insertBefore
as in the following example.
1 $.tmpl( "<li>${Name}</li>", { "Name" : "John Doe" }).appendTo( "#target" );
The template
parameter can be any of the following:
If data
is an array, the template is rendered once for each data item in the array. If data
is an object, or if the data
parameter is missing or null, a single template item is rendered.
The return value is a jQuery collection of elements made up of the rendered template items (one for each data item in the array). If the template contains only one top-level element, then there will be one element for each data item in the array.
To insert the rendered template items into the HTML DOM, the returned jQuery collection should not be inserted directly into the DOM, but should be chained with .appendTo
, .prependTo
, .insertAfter
or .insertBefore
, as in following example:
1 $.tmpl( myTemplate, myData ).appendTo( "#target" );
See also .tmpl().
The following example shows how to use jQuery.tmpl()
to render local data, using a template provided as a string:
1 var movies = [ 2 { Name: "The Red Violin", ReleaseYear: "1998" }, 3 { Name: "Eyes Wide Shut", ReleaseYear: "1999" }, 4 { Name: "The Inheritance", ReleaseYear: "1976" } 5 ]; 6 7 var markup = "<li><b>${Name}</b> (${ReleaseYear})</li>"; 8 9 // Compile the markup as a named template 10 $.template( "movieTemplate", markup ); 11 12 // Render the template with the movies data and insert 13 // the rendered HTML under the "movieList" element 14 $.tmpl( "movieTemplate", movies ) 15 .appendTo( "#movieList" );
Typically the data is not local and is instead obtained using an Ajax request to a remote service or page, as in the following example:
1 var markup = "<li><b>${Name}</b> (${ReleaseYear})</li>"; 2 3 // Compile the markup as a named template 4 $.template( "movieTemplate", markup ); 5 6 $.ajax({ 7 dataType: "jsonp", 8 url: moviesServiceUrl, 9 jsonp: "$callback", 10 success: showMovies 11 }); 12 13 // Within the callback, use .tmpl() to render the data. 14 function showMovies( data ) { 15 // Render the template with the "movies" data and insert 16 // the rendered HTML under the 'movieList' element 17 $.tmpl( "movieTemplate", data ) 18 .appendTo( "#movieList" ); 19 }
You can get the markup for the template from inline markup in the page, or from a string (possibly computed, or obtained remotely). For an example of how to use inline markup, see .tmpl().
When a template is rendered, the markup is first converted into a compiled-template function. Every time $.tmpl( markup , myData ).appendTo( "#target" )
is called, the template is recompiled. If the same template is to be used more than once for rendering data, you should ensure that the compiled template is cached. To cache the template when using markup that is obtained from a string (rather than from inline markup in the page), use $.template( name, markup )
to create a named template for reuse. See jQuery.template().
Template tags such as the ${}
tag can used within jQuery templates in addition to text and HTML markup to enable a number of scenarios such as composition of templates, iteration over hierarchical data, parameterization of template rendering, etc. Template tags can render content based on the values of data item fields or template variables such as $item
(corresponding to the template item), as well as expressions and function calls. See the documentation topics for each template tag: ${}, {{each}}, {{if}}, {{else}}, {{html}}, {{tmpl}} and {{wrap}}.
options
Parameter, and Template ItemsEach template item (the result of rendering a data item with the template) is associated with a tmplItem
data structure, which can be accessed using jQuery.tmplItem() and .tmplItem(), or the $item
template variable. Any fields or anonomyous methods passed in with the options
parameter of jQuery.tmpl()
will extend the tmplItem
data structure, and so be available to the template as in the following example:
1 var markup = "<li>Some content: ${$item.myMethod()}.<br/>" 2 + " More content: ${$item.myValue}.</li>"; 3 4 // Compile the markup as a named template 5 $.template( "movieTemplate", markup ); 6 7 // Render the template with the movies data 8 $.tmpl( "movieTemplate", movies, 9 { 10 myValue: "somevalue", 11 myMethod: function() { 12 return "something"; 13 } 14 } 15 ).appendTo( "#movieList" );
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <script src="http://code.jquery.com/jquery-latest.min.js"></script> 5 <script src="http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"></script> 6 </head> 7 <body> 8 9 <ul id="movieList"></ul> 10 11 <script> 12 var movies = [ 13 { Name: "The Red Violin", ReleaseYear: "1998" }, 14 { Name: "Eyes Wide Shut", ReleaseYear: "1999" }, 15 { Name: "The Inheritance", ReleaseYear: "1976" } 16 ]; 17 18 var markup = "<li><b>${Name}</b> (${ReleaseYear})</li>"; 19 20 /* Compile the markup as a named template */ 21 $.template( "movieTemplate", markup ); 22 23 /* Render the template with the movies data and insert 24 the rendered HTML under the "movieList" element */ 25 $.tmpl( "movieTemplate", movies ) 26 .appendTo( "#movieList" ); 27 </script> 28 29 </body> 30 </html>
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <script src="http://code.jquery.com/jquery-latest.min.js"></script> 5 <script src="http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"></script> 6 </head> 7 <body> 8 9 <button id="cartoonsBtn">Cartoons</button> 10 <button id="dramaBtn">Drama</button> 11 12 <ul id="movieList"></ul> 13 14 <script> 15 var markup = "<li><b>${Name}</b> (${ReleaseYear})</li>"; 16 17 /* Compile the markup as a named template */ 18 $.template( "movieTemplate", markup ); 19 20 function getMovies( genre, skip, top ) { 21 $.ajax({ 22 dataType: "jsonp", 23 url: "http://odata.netflix.com/Catalog/Genres('" + genre 24 + "')/Titles?$format=json&$skip=" 25 + skip + "&$top=" + top, 26 jsonp: "$callback", 27 success: function( data ) { 28 /* Get the movies array from the data */ 29 var movies = data.d; 30 31 /* Remove current set of movie template items */ 32 $( "#movieList" ).empty(); 33 34 /* Render the template items for each movie 35 and insert the template items into the "movieList" */ 36 $.tmpl( "movieTemplate", movies ) 37 .appendTo( "#movieList" ); 38 } 39 }); 40 } 41 42 $( "#cartoonsBtn" ).click( function() { 43 getMovies( "Cartoons", 0, 6 ); 44 }); 45 46 $( "#dramaBtn" ).click( function() { 47 getMovies( "Drama", 0, 6 ); 48 }); 49 50 </script> 51 52 </body> 53 </html>
1 import $ from '@codevadmin/jquery-tmpl'; 2 3 const markup = "<li><b>${Name}</b> (${ReleaseYear})</li>"; 4 5 /* Compile the markup as a named template */ 6 $.template( "movieTemplate", markup ); 7 8 function getMovies( genre, skip, top ) { 9 $.ajax({ 10 dataType: "jsonp", 11 url: "http://odata.netflix.com/Catalog/Genres('" + genre 12 + "')/Titles?$format=json&$skip=" 13 + skip + "&$top=" + top, 14 jsonp: "$callback", 15 success: function( data ) { 16 /* Get the movies array from the data */ 17 var movies = data.d; 18 19 /* Remove current set of movie template items */ 20 $( "#movieList" ).empty(); 21 22 /* Render the template items for each movie 23 and insert the template items into the "movieList" */ 24 $.tmpl( "movieTemplate", movies ) 25 .appendTo( "#movieList" ); 26 } 27 }); 28 } 29 30 $( "#cartoonsBtn" ).click( function() { 31 getMovies( "Cartoons", 0, 6 ); 32 }); 33 34 $( "#dramaBtn" ).click( function() { 35 getMovies( "Drama", 0, 6 ); 36 });
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More