Giter VIP home page Giter VIP logo

jinja.js's Introduction

Jinja.js

Client-side rendering of Twig/Jinja/Jinjs templates.


Demos

You can find demos under the /tests folder:


Get Started

1. Include Script

<script src="lib/jinja.min.js"></script>

2. Add HTML Markup

<script type="text/jinja" id="standalone">
    <h1>Welcome to {{ title|capitalize}}!</h1>
</script>

3. Render

a. jQuery

<script src="lib/jinja.jquery.js"></script>
...
<script>
    // Replace #content with rendered template
    $('#content').jinja({ title: 'jinja.js' });
</script>

b. Vanilla Javascript

<script>
    var script      = document.getElementById('standalone');
    var template    = script.innerHTML;
    var context     = { title: 'jinja.js' };
    var content     = Jinja.render(template, context);

    document.write(content);

    // or

    var container = document.createElement('div');
    container.innerHTML = content;
    script.parentNode.replaceChild(container, script);
</script>

Building

A quick build script is included at bin/build that will install dependencies, compile & compress:

$ ./bin/build
npm info it worked if it ends with ok
npm info using [email protected]
…
Finished!

This will create:

  • build/build.js -> lib/jinja.js
  • build/build.min.js -> lib/jinja.min.js

Requirements


Author


See Also

jinja.js's People

Contributors

ericclemmons avatar corbinbs avatar timoxley avatar

Watchers

James Cloos 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.