![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
http://github.com/jquery/jquery-tmpl
http://api.jquery.com/category/plugins/templates/
Note: currently not implemented: wrap tag and tmplItem method.
http://docs.djangoproject.com/en/dev/topics/templates/
npm install jqtpl
$ make test
var jqtpl = require("jqtpl");
Compile and render a template. It uses jqtpl.template
method.
markup
html code stringdata
object or array of dataoptions
optional options objectNamed templates - there is a way to precompile the template using a string, so you can render this template later using its name. Template is cached after this fn call.
// tpl
<div>${a}</div>
// code
// precompile an cache it
jqtpl.template( "templateName", tpl );
// render
jqtpl.tmpl( "templateName", {a:1} );
// you can also delete the template from cache
delete jqtpl.template["templateName"];
// output
<div>1</div>
$data
- data object passed to render method$item
- contains $data via $item.data as well as user options - an optional map of user-defined key-value pairs.Examples:
// tpl
<div>${ $item.someMethod() }</div>
// code
jqtpl.tmpl( tpl, {a:1}, {
someMethod: function(){ return 1; }
});
//output
<div>1</div>
// tpl
<div>${a}</div>
// code
jqtpl.tmpl( tpl, {a:123});
// output
<div>123</div>
//tpl
<div>${a}</div>
// code
jqtpl.tmpl( tpl, [{a:1},{a:2},{a:3}]);
// output
<div>1</div><div>2</div><div>3</div>
// tpl
<div>${a}</div>
// code
jqtpl.tmpl( tpl, {
a:function() {
return 1 + 5;
}
});
//output
<div>6</div>
// tpl
{{if a == 6}}
<div>${a}</div>
{{else a == 5}}
<div>5</div>
{{else}}
<div>a is not 6 and not 5</div>
{{/if}}
// code
jqtpl.tmpl( tpl, {a:6});
// output
<div>6</div>
// code
jqtpl.tmpl( tpl, {a:5});
// output
<div>a is not 6</div>
// tpl
{{each(i, name) names}}
<div>${i}.${name}</div>
{{/each}}
// alternative syntax
{{each names}}
<div>${$index}.${$value}</div>
{{/each}}
// code
jqtpl.tmpl( tpl, {names: ["A", "B"]});
// output
<div>0.A</div><div>1.B</div>
// tpl
<div>{{html a}}</div>
// code
jqtpl.tmpl( tpl, {a:'<div id="123">2</div>'});
// output
<div id="123">2</div>
// tpl
<div>{{! its a comment}}</div>
// code
jqtpl.tmpl( tpl );
// output
<div></div>
Note: passing json object with 2 curly brackets without any separation will break the engine: {{tmpl({a: {b: 1}}) "mypartial"}}
// tpl
<div>{{tmpl({name: "Test"}) '${name}'}}</div>
// code
jqtpl.tmpl(tpl);
// output
<div>Test</div>
If you want to skip a part of your template, which should be rendered on the client, you can use now verbatim tag.
// mytemplate.html
<div>my name is ${name}</div>
{{verbatim}}
<div>your name is ${userName}</div>
{{/verbatim}}
// code
res.render('myaction', {name: 'Kof'});
// output
<div>my name is Kof</div>
<div>your name is ${userName}</div>
Note: express is caching all templates in production!
app.set("view engine", "html");
app.register(".html", require("jqtpl").express);
Read express documentation here http://expressjs.com/guide.html#res.partial()
// tpl
// myaction.html
<div>{{partial(test) "mypartial"}}</div>
// mypartial.html
${name}
// code
app.get('/myaction', function(req, res) {
res.render('myaction', {test: {name: 'Test'}});
})
// output
<div>Test</div>
Using array of data:
// tpl
// myaction.html
<div id="main">
{{partial(test) "mypartial"}}
</div>
// mypartial.html
<div class="partial">
${name}
</div>
// code
app.get('/myaction', function(req, res) {
res.render('myaction', {
as: global,
test: [
{name: "Test1"},
{name: "Test2"}
]
});
})
// output
<div id="main">
<div class="partial">Test1</div>
<div class="partial">Test2</div>
</div>
Using layout tag in a view it is possible to define a layout within this view. Note: it is possible since express@2.2.1.
// tpl
// mylayout.html
<html>
{{html body}}
</html>
// myview.html
{{layout "mylayout"}}
<div>myview</div>
// output
<html>
<div>myview</div>
</html>
FAQs
A template engine for nodejs, browser and any other javascript environment
We found that jqtpl demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.