{{title}}
{{body}}
I\'m trying to work with requirejs and text plugin and I have weird problem.
I have two web servers:
As another alternative way you can use jQuery get method to fetch the content of the template as plain text and then compile it with Handlebars. I came to this solution as a last resort after spending several hours into forums reading about issues with require.js text plugin and CORS. Here's an example :
The template :
Default
{{title}}
{{body}}
The js script :
var deps = [
'jquery',
'handlebars',
];
require(deps, function($, handlebars){
var template = 'https://your_site/raw.templates/basic.handlebars';
$.get(template, function( data, textStatus, jqxhr ) {
var Handlebars = handlebars;
var basicTemplate = Handlebars.compile(data);
var context = {title: "My New Post", body: "This is my first post!"};
var html = basicTemplate(context);
var grid = document.createElement('div');
grid.setAttribute('id', 'itemsGrid');
grid.innerHTML = html;
document.body.appendChild(grid);
});
});