mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-17 19:21:04 +01:00
simplifying conditional logic in templates + fixed it so that it takes namespace into account
This commit is contained in:
@@ -255,19 +255,6 @@
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getConditionalBlock(regex, block, template) {
|
|
||||||
data = template.match(regex);
|
|
||||||
if (data == null) return;
|
|
||||||
|
|
||||||
if (self.blocks && block !== undefined) self.blocks[block] = data[0];
|
|
||||||
|
|
||||||
data = data[0]
|
|
||||||
.replace("<!-- IF " + block + " -->", "")
|
|
||||||
.replace("<!-- ENDIF " + block + " -->", "");
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
function setBlock(regex, block, template) {
|
function setBlock(regex, block, template) {
|
||||||
return template.replace(regex, block);
|
return template.replace(regex, block);
|
||||||
}
|
}
|
||||||
@@ -317,14 +304,12 @@
|
|||||||
block = parse(data[d], namespace, block);
|
block = parse(data[d], namespace, block);
|
||||||
template = setBlock(regex, block, template);
|
template = setBlock(regex, block, template);
|
||||||
} else {
|
} else {
|
||||||
var conditional = makeConditionalRegex(d),
|
var conditional = makeConditionalRegex(namespace + d);
|
||||||
block = getConditionalBlock(conditional, namespace, template);
|
|
||||||
|
|
||||||
if (block && !data[d]) {
|
if (conditional.test(template) && !data[d]) {
|
||||||
template = template.replace(conditional, '');
|
template = template.replace(conditional, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template = replace(namespace + d, data[d], template);
|
template = replace(namespace + d, data[d], template);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user