Add {include} support to WCF.Template
authorTim Düsterhus <duesterhus@woltlab.com>
Fri, 9 Jan 2015 18:07:11 +0000 (19:07 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Fri, 9 Jan 2015 18:13:44 +0000 (19:13 +0100)
It automatically calls fetch() on the specified variable and passes
all given variables along.

wcfsetup/install/files/js/WCF.js

index 276508f56c649872f4b3c9d9edd0f81d8bc2b5b0..4e2b0e4a87bfcd785e51f2dea8f43b04a1bc4d89 100755 (executable)
@@ -4653,6 +4653,17 @@ WCF.Template = Class.extend({
                .replace(/\{lang\}(.+?)\{\/lang\}/g, function(_, content) {
                        return "' + WCF.Language.get('" + unescape(content) + "') + '";
                })
+               // {include}
+               .replace(/\{include (.+?)\}/g, function(_, content) {
+                       content = content.replace(/\\\\/g, '\\').replace(/\\'/g, "'");
+                       var $parameters = parseParameterList(content);
+                       
+                       if (typeof $parameters['file'] === 'undefined') throw new Error('Missing file attribute in include-tag');
+                       
+                       $parameters['file'] = $parameters['file'].replace(/\$([^.\[\(\)\]\s]+)/g, "(v.$1)");
+                       
+                       return "' + " + $parameters['file'] + ".fetch(v) + '";
+               })
                // {if}
                .replace(/\{if (.+?)\}/g, function(_, content) {
                        content = unescape(content.replace(/\$([^.\[\(\)\]\s]+)/g, "(v['$1'])"));