added templates.setGlobal - allows you to add default template vars that are sent to all tpls upon parsing; added relative_path as global

v1.18.x
psychobunny 11 years ago
parent 487281cc7a
commit fda68bc5dd

@ -97,6 +97,8 @@
notifications = require('./src/notifications'),
upgrade = require('./src/upgrade');
templates.setGlobal('relative_path', nconf.get('relative_path'));
upgrade.check(function(schema_ok) {
if (schema_ok || nconf.get('check-schema') === false) {
websockets.init(SocketIO);

@ -468,6 +468,8 @@ var socket,
app.alternatingTitle('');
});
templates.setGlobal('relative_path', RELATIVE_PATH);
});
showWelcomeMessage = location.href.indexOf('loggedin') !== -1;

@ -6,7 +6,9 @@
available_templates = [],
parsed_variables = {};
module.exports = templates = {};
module.exports = templates = {
"globals": {}
};
try {
fs = require('fs');
@ -242,6 +244,10 @@
parsed_variables[key] = value;
}
templates.setGlobal = function(key, value) {
templates.globals[key] = value;
}
//modified from https://github.com/psychobunny/dcp.templates
var parse = function (data) {
var self = this;
@ -282,6 +288,13 @@
var template = this.html,
regex, block;
// registering globals
for (var g in templates.globals) {
if (templates.globals.hasOwnProperty(g)) {
data[g] = data[g] || templates.globals[g];
}
}
return (function parse(data, namespace, template, blockInfo) {
if (!data || data.length == 0) {
template = '';

Loading…
Cancel
Save