Skip to content

Commit

Permalink
better escaping examples
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed May 10, 2012
1 parent ad1de61 commit 4dbd020
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 26 deletions.
36 changes: 10 additions & 26 deletions lib/Mojo/Template.pm
Expand Up @@ -414,20 +414,21 @@ the default in L<Mojolicious> C<.ep> templates for example.
<%= Perl expression, replaced with XML escaped result %>
<%== Perl expression, replaced with result %>
L<Mojo::ByteStream> objects are always excluded from automatic escaping.
<%= Mojo::ByteStream->new('<div>excluded!</div>') %>
You can use escaped tags and lines to generate templates.
%% my $number = <%= 20 + 3 %>;
The number is <%%= $number %>
A newline can be escaped with a backslash.
This is <%= 23 * 3 %> a\
Newlines can be escaped with a backslash.
This is <%= 1 + 1 %> a\
single line
And a backslash in front of a newline can be escaped with another backslash.
% use Data::Dumper;
This will\\
result <%= Dumper {foo => 'bar'} %>\\
in multiple lines
This will <%= 1 + 1 %> result\\
in multiple\\
lines
=head2 Trimming
Expand Down Expand Up @@ -481,23 +482,6 @@ stringify to error messages with context.
5: %= $i * 2
6: </body>
=head2 Caching
L<Mojo::Template> does not support caching by itself, but you can easily build
a wrapper around it.
# Compile and store code somewhere
my $mt = Mojo::Template->new;
$mt->parse($template);
$mt->build;
my $code = $mt->code;
# Load code and template (template for debug trace only)
$mt->template($template);
$mt->code($code);
$mt->compile;
my $output = $mt->interpret(@args);
=head1 ATTRIBUTES
L<Mojo::Template> implements the following attributes.
Expand Down
11 changes: 11 additions & 0 deletions lib/Mojolicious/Guides/Rendering.pod
Expand Up @@ -116,6 +116,17 @@ Only L<Mojo::ByteStream> objects are excluded from automatic escaping.

<%= Mojo::ByteStream->new('<p>test</p>') %>

Newlines can be escaped with a backslash.

This is <%= 1 + 1 %> a\
single line

And a backslash in front of a newline can be escaped with another backslash.

This will <%= 1 + 1 %> result\\
in multiple\\
lines

You can also add an additional equal sign to the end of a tag to have it
automatically remove all surrounding whitespace, this allows free indenting
without ruining the result.
Expand Down

0 comments on commit 4dbd020

Please sign in to comment.