Skip to content

Node.js based forum software built for the modern web

added if / else logic to templates

psychobunny2d7228fa40cd
diff --git a/public/src/templates.js b/public/src/templates.js
index 763c7fe940..d36941bf72 100644
--- a/public/src/templates.js
+++ b/public/src/templates.js
@@ -306,8 +306,25 @@
} else {
var conditional = makeConditionalRegex(namespace + d);
- if (conditional.test(template) && !data[d]) {
- template = template.replace(conditional, '');
+ var conditionalBlock = conditional.exec(template);
+
+ if (conditionalBlock !== null) {
+ conditionalBlock = conditionalBlock[0].split('<!-- ELSE -->');
+
+ if (conditionalBlock[1]) {
+ // there is an else statement
+ if (!data[d]) {
+ template = template.replace(conditional, conditionalBlock[1]);
+ } else {
+ template = template.replace(conditional, conditionalBlock[0]);
+ }
+
+ } else {
+ // regular if
+ if (!data[d]) {
+ template = template.replace(conditional, '');
+ }
+ }
}
template = replace(namespace + d, data[d], template);