GithubHelp home page GithubHelp logo

jquery.tpl's Introduction

jQuery.tpl project: simple, fast and powerfull templates for jQuery and javascript (github.com/donnerjack13589/jsTPL).

It’s easy to learn - start now!

Basic examples:

$.template(“1 + 1 = {%= 1+1 %}”) .html(); // 1 + 1 = 2 $.template(“Hello {%= a %}!”,[“a”]) .html({a: ‘World’}); // >> Hello World! $.template(“Hello {%each a%}{%= this %}, {%/each%}world!”,) .html({a: [‘Andy’,‘Alex’]}); // >> Hello Andy, Alex, World! $.template(“{%if godmode%}My Lord!{%else%}Who are you?{%/if%}”,[“godmode”]) .html({godmode: true}); // >> My Lord!

Medium examples:

$.template(“{%catch var a %}What’s up, dude?{%/catch%} {%= a.substr(0,9) %}?”) .html(); // >> What’s up? $.template(“{%~ var a = true; %}{%if !a %}‘a’ is false?{%/if%}”,[“a”]) .html(); // >> ‘a’ is false? $.template(“{%@ name(value) { return ‘~’ + value + ‘~’ } %}{%= name(‘fancy’)%}”) .html() // >>~fancy~

Harder examples:

$.template(“&lt;div&gt;&lt;/div&gt;”)(); // &gt;&gt; jQuery object of “div” $.template(“<div></div>”,[],“name”); // Store this template by “name” $.template(“name”)(); // &gt;&gt; jQuery object of “div” again $.template(“<button>{%= value%}</button>”,,“input”); $.template(“{%: input {value:‘Hello world!’} %}”)(); // &gt;&gt; Button with text “Hello world!” $.template(“{%catch var temp%}<button>{%= value%}</button>{%/catch%}\ {%= $(temp).click(function(){alert(msg)}) %}”,[“value”,“msg”],“input”); $.template(“{%: input {value:‘Hello world!’, msg: ‘Alarm!’} %}”)(); // >> Button with text “Hello world!” and alerting “Alarm!” on click

Block module

$.template(“&lt;div&gt;Hello, {%block ‘username’%}{%/block%}!&lt;/div&gt;”,[],“block”); $.template(“{%extends ‘block’%}{%block ‘username’%}Admin{%/block%}”)().html(); // >> Hello, Admin!

jquery.tpl's People

Contributors

indutny avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.