Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Created September 1, 2010 08:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/560392 to your computer and use it in GitHub Desktop.
Save anonymous/560392 to your computer and use it in GitHub Desktop.
diff --git i/t/mojo/template.t w/t/mojo/template.t
index 869fcb2..db281e6 100644
--- i/t/mojo/template.t
+++ w/t/mojo/template.t
@@ -23,7 +23,7 @@ package main;
use strict;
use warnings;
-use Test::More tests => 95;
+use Test::More tests => 96;
use File::Spec;
use File::Temp;
@@ -427,6 +427,25 @@ $output = $mt->render(<<'EOF');
EOF
is($output, "<html>\n1234</html>\n", 'clean multiline loop');
+# Recursive template call
+$mt = Mojo::Template->new;
+$output = $mt->render(<<'EOF');
+<% sub list { =%>
+<% my $t = shift; =%>
+<ul>
+<% for my $n (@$t) { =%>
+<li><%= $n->{name} =%>
+<% if (exists($n->{tree})) { =%>
+<%= list($n->{tree}) =%>
+<% } =%>
+</li>
+<% } =%>
+</ul>
+<% } =%>
+<%= list([{id=>1,name=>"root",tree=>[{id=>2,name=>"le"}]}]) %>
+EOF
+is($output, "<ul><li>root<ul><li>le</li></ul></li></ul>", 'recursive template call');
+
# Escaped line ending
$mt = Mojo::Template->new;
$output = $mt->render(<<'EOF');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment