Here are a few examples how to use Barbe in different cases.
<script type="text/html" id="template_static" data-anchor="anchor_static">
This is a static template
</script>
new Barbe.View("template_static").grow();
<script type="text/html" id="template_partial" data-anchor="anchor_partial">
Include another template: {{>template_static}}
</script>
new Barbe.View("template_partial").grow();
<script type="text/html" id="template_basic" data-anchor="anchor_basic">
This is a basic template created with <em>{{ name }}</em>.
</script>
new Barbe.View("template_basic", {data: {name: "Barbe.js"}}).grow();
<script type="text/html" id="template_anchor">
This is a template created with <em>{{ name }}</em> and the anchor is defined with the constructor.
</script>
new Barbe.View("template_anchor", {data: {name: "Barbe.js"}}, "anchor_anchor").grow();
<script type="text/html" id="template_success" data-anchor="anchor_success">
This is a template created with {{ name }} and the data has been altered: {{ nameUpperCase }}.
</script>
new Barbe.View("template_success", {
data: {name: "Barbe.js"},
success: function (response) {
response.nameUpperCase = response.name.toUpperCase();
}
}).grow();
<script type="text/html" id="template_api" data-anchor="anchor_api>
{{#data}}
{{name}}
{{/data}}
</script>
new Barbe.View("template_api", {
url: "https://api.github.com/users/boertel",
dataType: "jsonp"
}).grow();
<script type="text/html" id="template_api_advanced" data-anchor="anchor_api_advanced>
{{#data}}
Login: {{login}}<br>
Location: {{location}}<br>
Created at: {{created_at}}<br>
{{/data}}
</script>
new Barbe.View("template_api_advanced", {
url: "https://api.github.com/users/boertel",
dataType: "jsonp",
success: function (response) {
response.data.created_at = new Date(response.data.created_at);
}
}).grow();