1.3.5 • Published 10 years ago

mini-template-engine v1.3.5

Weekly downloads
1
License
MIT
Repository
github
Last release
10 years ago

Mini template engine.

Travis Code Climate

This is a small easy template engine. It just replaces variable placeholders with objects passed to the function.

Install

npm install --save mini-template-engine

Syntax

var template = require('mini-template-engine');
template(
    'string with {placeholder}',
    { placeholder: 'to be replaced' },
    function asyncCallback(data, error) {} // Optional. If not used it'll be blocking.
);

Usage

var template = require('mini-template-engine');

var html = template(
    '<div class="{className}">{content}</div>',
    {
        className: 'wrapper',
        content: 'So this is some not so useful content'
    }
);

console.log(html);

// Template should now contain this html string:
// '<div class="wrapper">So this is some not so useful content</div>'


// Async approach
var async = template(
    '<span>{async}</span>',
    { async: 'loaded async' },
    function(template, err) {
        if (err) {
            console.log(err);
        }

        console.log(template);
    }
);

// Output: <span>loaded async</span>


// You can also use the "template" for other stuff than html also
var otherStuff = template(
    'I want to add a word dynamic: {word}',
    {
        word: 'JavaScript'
    }
);

console.log(otherStuff);

// Output:
// 'I want to add a word dynamic: JavaScript'

var nested = template(
    '<div class="{className}">{nested.content}</div>',
    {
        className: 'wrapper',
        nested: {
            content: 'So this is some not so useful content'
        }
    }
);

console.log(nested);

// Template should now contain this html string:
// '<div class="wrapper">So this is some not so useful content</div>'
1.3.5

10 years ago

1.3.4

10 years ago

1.2.4

10 years ago

1.1.4

10 years ago

1.1.3

10 years ago

1.1.2

10 years ago

1.1.1

10 years ago

1.1.0

10 years ago

1.0.0

10 years ago