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.
- Host: GitHub
- URL: https://github.com/ramsunvtech/underscore.templates
- Owner: ramsunvtech
- Created: 2014-01-14T10:59:03.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2014-05-19T10:22:51.000Z (about 12 years ago)
- Last Synced: 2025-01-24T06:12:57.566Z (over 1 year ago)
- Language: JavaScript
- Size: 207 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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
- _.tpl()
- _.subTpl()
- _.mergeTpl()
- _.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);