An open API service indexing awesome lists of open source software.

https://github.com/ramsunvtech/underscore.templates

This is Underscore Mixin for Sub Templates with Recursive Template and Merging Multiple Templates.
https://github.com/ramsunvtech/underscore.templates

Last synced: 9 months ago
JSON representation

This is Underscore Mixin for Sub Templates with Recursive Template and Merging Multiple Templates.

Awesome Lists containing this project

README

          

Underscore.Templates
====================

This Underscore Mixin used for creating Sub Templates for Recursive Templates and for Merging Multiple Templates.

How it Works?


This Mixin will store the Sub Templates data in to Custom Underscore Property called "_.tplBuffer" as a Array Object.


The Created Sub Templates will be used when you use Recursive Templates / Merge Templates.

Available Mixins




  1. _.tpl()

  2. _.subTpl()

  3. _.mergeTpl()

  4. _.mergeSubTpl()

How to Use Sub Template then Merge to Main Template?.


1. Expected Output which has Header as Main Template and Menu as Sub Template


```html







```

2. Creating Menu Template as Sub Template


// `menu` variable is used as a Main Object inside Template.
var tplData = '

';

// JSON Object of Template Data.
var tplVars = {
"items": [{
"href": "#education",
"title": "Education"
},{
"href": "#photos",
"title": "My Photos"
}]
};

// This will compile the Template and Store in to Template Buffer, which can be used while merge Templates.
_.subTpl('menu', tplData, tplVars);

2. Creating Main Template as Header Template and Compiled Menu data Will be Available inside the Template.


// `header` variable is used as a Main Object inside Template.
// `header.menu` will be retrieved from Template Buffer and Added to Template JSON Data.
var tplData = '





';

// JSON Object of Template Data.
// `header.menu` will be retrieved from Template Buffer and Added to Template JSON Data.
var tplVars = {
"siteName": "Your Site Name"
};

// This will compile the Template and Merge dependent Templates from Buffer.
_.mergeTpl('header', tplData, tplVars);