Code Monkey home page Code Monkey logo

pokerface's Introduction

pokerface :|

A tiny lib to use html templates with JS

Dependecies

This lib uses jquery to work.

the jquery have to come before porkerface lib

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="js/pokerface.js"></script>

Usage

Create a template that you want and put the desired data between the pokerface delimiter :| |:

<div>
    <h1>:|my_title|:</h1>
</div>

Then in yout JS file, you can call the loadTemplate function using a Json Data. The key value must match with the value inside the :|my_title|:

var data = {
    'my_title':'Here comes a title'
}
loadTemplate('path_to_your_template/template.html', 
              JSON.stringify(data), 
              function(finalTemplate){
                    //Put the template whatever you want
                    $('#id_title').html(finalTemplate);
              });

You can use a JsonArray to loop through a template and get a list of templates filled with data. Use this to fill lists and tables.

Example:

    //Build the array
    //... another code
    var array = [];
    $(my_iterable).each(function () {
        var data = {
            'name': this.name,
            'email': this.email
        };
        array.push(data);
    });

    var tbody = $("#my_table");
    loadTemplateList('path_to_your_template/template.html', JSON.stringify(array), 
    function (template_filled) {
        tbody.append(template_filled);
        //... whathever you wanto to execute when done loading the template
    });

have fun!

pokerface's People

Contributors

hildepedroni avatar

Watchers

 avatar Cedric Matheus 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.