Skip to content

Node.js based forum software built for the modern web

prevent a potentially badly written theme.json from blowing up your forum

psychobunny30a45ee78ef9
diff --git a/public/src/templates.js b/public/src/templates.js
index 3329d2782b..2adb4553de 100644
--- a/public/src/templates.js
+++ b/public/src/templates.js
@@ -61,26 +61,37 @@
function loadServer() {
var loaded = templatesToLoad.length;
- for (var t in templatesToLoad) {
- (function (file) {
- fs.readFile((customTemplateDir ? customTemplateDir : __dirname + '/../templates') + '/' + file + '.tpl', function (err, html) {
- var template = function () {
- this.toString = function () {
- return this.html;
- };
- }
-
- template.prototype.file = file;
- template.prototype.parse = parse;
- template.prototype.html = String(html);
-
- global.templates[file] = new template;
-
- loaded--;
- if (loaded == 0) templates.ready();
- });
- }(templatesToLoad[t]));
+ function getTemplates(directory) {
+ for (var t in templatesToLoad) {
+ (function (file) {
+ fs.readFile(directory + '/' + file + '.tpl', function (err, html) {
+ var template = function () {
+ this.toString = function () {
+ return this.html;
+ };
+ }
+
+ template.prototype.file = file;
+ template.prototype.parse = parse;
+ template.prototype.html = String(html);
+
+ global.templates[file] = new template;
+
+ loaded--;
+ if (loaded == 0) templates.ready();
+ });
+ }(templatesToLoad[t]));
+ }
+ }
+ if (customTemplateDir) {
+ fs.exists(customTemplateDir, function (exists) {
+ var directory = (exists ? customTemplateDir : __dirname + '/../templates');
+ getTemplates(customTemplateDir);
+ });
+ } else {
+ getTemplates(__dirname + '/../templates');
}
+
}
function loadClient() {