templates.js 586 Bytes
Newer Older
1
define(['jquery', 'underscore'], function($, _) {
2 3 4 5 6 7
    /**
     * Loads the named template from the page, or logs an error if it fails.
     * @param name The name of the template.
     * @returns The loaded template.
     */
    var loadTemplate = function(name) {
8
        var templateSelector = '#' + name + '-tpl',
9 10
            templateText = $(templateSelector).text();
        if (!templateText) {
11
            console.error('Failed to load ' + name + ' template');
12 13 14 15 16 17 18 19
        }
        return _.template(templateText);
    };

    return {
        loadTemplate: loadTemplate
    };
});