Skip to content

Node.js based forum software built for the modern web

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

psychobunnyfda68bc5dd7f
diff --git a/app.js b/app.js
index 2c56822907..54b9b0c8d5 100644
--- a/app.js
+++ b/app.js
@@ -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);
diff --git a/public/src/app.js b/public/src/app.js
index 6d889381c2..f379358e7a 100644
--- a/public/src/app.js
+++ b/public/src/app.js
@@ -468,6 +468,8 @@ var socket,
app.alternatingTitle('');
});
+
+ templates.setGlobal('relative_path', RELATIVE_PATH);
});
showWelcomeMessage = location.href.indexOf('loggedin') !== -1;
diff --git a/public/src/templates.js b/public/src/templates.js
index c451d982bf..23687bc515 100644
--- a/public/src/templates.js
+++ b/public/src/templates.js
@@ -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 = '';