=pod
L is a Mustache-like (L) template engine.
That means it tends to have no logic in template files.
=head2 Example
my $view = Text::Caml->new;
my $output = $view->render_file('template', {title => 'Hello', body => 'there!'});
# template
{{title}}
{{body}}
$output = $view->render('{{hello}}', {hello => 'hi'});
=head2 Syntax
=head3 Context
Context is the data passed to the template. Context can change during template
rendering and be specific in various cases.
=head3 Variables
Variables are inserted using C<{{foo}}> syntax. If a variable is not defined or
empty it is simply ignored.
Hello {{user}}!
By default every variable is escaped when parsed. This can be omitted using C<&>
flag.
# user is '1 > 2'
Hello {{user}}! => Hello 1 > 2!
Hello {{&user}}! => Hello 1 > 2!
Using a C<.> syntax it is possible to access deep hash structures.
# user => {name => 'Larry'}
{{user.name}}
Larry
=head3 Comments
Comments are ignored. They can be multiline too.
foo{{! Comment}}bar
foo{{!
Comment
}}bar
=head3 Sections
Sections are like iterators that iterate over your data. Depending on a
variable type different iterators are created.
=over 4
=item *
Boolean, C is defined, not zero and not empty.
# have_comments => 1
{{#have_comments}}
We have comments!
{{/have_comments}}
We have comments!
=item *
Array, C is a non-empty array reference. Special variable C<{{.}}> is
created to point to the current element.
# list => [1, 2, 3]
{{#list}}{{.}}{{/list}}
123
=item *
Hash, C is a non-empty hash reference. Context is swithed to to the
elements.
# hash => {one => 1, two => 2, three => 3}
{{#hash}}
{{one}}{{two}}{{three}}
{{/hash}}
123
=item *
Lambda, C is an anonymous subroutine, that's called with three
arguments: current object instance, template and the context. This can be used
for subrendering, helpers etc.
wrapped => sub {
my $self = shift;
my $text = shift;
return '' . $self->render($text, @_) . '';
};
{{#wrapped}}
{{name}} is awesome.
{{/wrapped}}
Willy is awesome.
=back
=head3 Inverted sections
Inverted sections are run in those situations when normal sections don't. When
boolean value is false, array is empty etc.
# repo => []
{{#repo}}
{{name}}
{{/repo}}
{{^repo}}
No repos :(
{{/repo}}
No repos :(
=head3 Partials
Partials are like C in other templates engines. They are run with the
current context and can be recursive.
{{#articles}}
{{>article_summary}}
{{/articles}}
=cut