mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-10 16:05:49 +01:00
added templates.setGlobal - allows you to add default template vars that are sent to all tpls upon parsing; added relative_path as global
This commit is contained in:
2
app.js
2
app.js
@@ -97,6 +97,8 @@
|
|||||||
notifications = require('./src/notifications'),
|
notifications = require('./src/notifications'),
|
||||||
upgrade = require('./src/upgrade');
|
upgrade = require('./src/upgrade');
|
||||||
|
|
||||||
|
templates.setGlobal('relative_path', nconf.get('relative_path'));
|
||||||
|
|
||||||
upgrade.check(function(schema_ok) {
|
upgrade.check(function(schema_ok) {
|
||||||
if (schema_ok || nconf.get('check-schema') === false) {
|
if (schema_ok || nconf.get('check-schema') === false) {
|
||||||
websockets.init(SocketIO);
|
websockets.init(SocketIO);
|
||||||
|
|||||||
@@ -468,6 +468,8 @@ var socket,
|
|||||||
|
|
||||||
app.alternatingTitle('');
|
app.alternatingTitle('');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
templates.setGlobal('relative_path', RELATIVE_PATH);
|
||||||
});
|
});
|
||||||
|
|
||||||
showWelcomeMessage = location.href.indexOf('loggedin') !== -1;
|
showWelcomeMessage = location.href.indexOf('loggedin') !== -1;
|
||||||
|
|||||||
@@ -6,7 +6,9 @@
|
|||||||
available_templates = [],
|
available_templates = [],
|
||||||
parsed_variables = {};
|
parsed_variables = {};
|
||||||
|
|
||||||
module.exports = templates = {};
|
module.exports = templates = {
|
||||||
|
"globals": {}
|
||||||
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fs = require('fs');
|
fs = require('fs');
|
||||||
@@ -242,6 +244,10 @@
|
|||||||
parsed_variables[key] = value;
|
parsed_variables[key] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
templates.setGlobal = function(key, value) {
|
||||||
|
templates.globals[key] = value;
|
||||||
|
}
|
||||||
|
|
||||||
//modified from https://github.com/psychobunny/dcp.templates
|
//modified from https://github.com/psychobunny/dcp.templates
|
||||||
var parse = function (data) {
|
var parse = function (data) {
|
||||||
var self = this;
|
var self = this;
|
||||||
@@ -282,6 +288,13 @@
|
|||||||
var template = this.html,
|
var template = this.html,
|
||||||
regex, block;
|
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) {
|
return (function parse(data, namespace, template, blockInfo) {
|
||||||
if (!data || data.length == 0) {
|
if (!data || data.length == 0) {
|
||||||
template = '';
|
template = '';
|
||||||
|
|||||||
Reference in New Issue
Block a user