Subject: | Patch for CAPTURE block implementation |
Support for capturing anonymous block output:
[% txt = BLOCK %]
content
[% END %]
The attached patch provides a simple implementation for the above
construct based on Template::Directive's implementation. Should handle
nested directives just like the Perl version.
cheers,
Tom
Subject: | 2009-03-03-jemplate-directive.patch |
--- /usr/local/share/perl/5.8.8/Jemplate/Directive.pm 2008-03-29 21:13:43.000000000 +0000
+++ /tmp/Directive.pm 2009-03-03 13:11:31.000000000 +0000
@@ -566,7 +566,27 @@
}
sub capture {
- return "throw('CAPTURE not yet supported in Jemplate');";
+ my ($class, $name, $block) = @_;
+
+ if (ref $name) {
+ if (scalar @$name == 2 && ! $name->[1]) {
+ $name = $name->[0];
+ }
+ else {
+ $name = '[' . join(', ', @$name) . ']';
+ }
+ }
+
+ return <<EOF;
+
+// CAPTURE
+(function() {
+ var output = '';
+ $block
+ stash.set($name, output);
+})();
+EOF
+
}
BEGIN {