diff --git a/public/src/templates.js b/public/src/templates.js index cb153ed10d..5e9d5e35f5 100644 --- a/public/src/templates.js +++ b/public/src/templates.js @@ -227,6 +227,10 @@ return new RegExp("[\\s\\S]*", 'g'); } + function makeConditionalRegex(block) { + return new RegExp("[\\s\\S]*", 'g'); + } + function getBlock(regex, block, template) { data = template.match(regex); if (data == null) return; @@ -240,6 +244,19 @@ 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("", "") + .replace("", ""); + + return data; + } + function setBlock(regex, block, template) { return template.replace(regex, block); } @@ -289,6 +306,14 @@ block = parse(data[d], namespace, block); template = setBlock(regex, block, template); } else { + var conditional = makeConditionalRegex(d), + block = getConditionalBlock(conditional, namespace, template); + + if (block && !data[d]) { + template = template.replace(conditional, ''); + } + + template = replace(namespace + d, data[d], template); } }