HP-Handy
view release on metacpan or search on metacpan
lib/HP/Handy.pm view on Meta::CPAN
{%- tag -%} Strip whitespace before and after the tag
=head2 Variables
{{ name }}
{{ user.email }}
{{ items[0] }}
{{ config["debug"] }}
=head2 Filters
{{ name | upper }}
{{ text | truncate(80) }}
{{ text | replace("old", "new") }}
{{ value | default("n/a") }}
{{ items | join(", ") }}
=head2 Tests
{% if x is defined %}
{% if n is odd %}
{% if x is divisibleby 3 %}
{% if x is not none %}
=head2 Conditional
{% if condition %}
...
{% elif other %}
...
{% else %}
...
{% endif %}
Inline conditional:
{{ "yes" if flag else "no" }}
=head2 For Loop
{% for item in list %}
{{ loop.index }}: {{ item }}
{% endfor %}
{% for item in list if item != '' %}
{{ item }}
{% else %}
(empty)
{% endfor %}
Loop variable C<loop>:
loop.index 1-based counter
loop.index0 0-based counter
loop.revindex reverse counter (1-based)
loop.revindex0 reverse counter (0-based)
loop.first true on first iteration
loop.last true on last iteration
loop.length total number of items
loop.odd true on odd iterations
loop.even true on even iterations
Dict iteration:
{% for key, value in mapping %}
{{ key }}: {{ value }}
{% endfor %}
=head2 Set
{% set x = 42 %}
{% set greeting = "Hello, " ~ name %}
=head2 Include
{% include "header.html" %}
{% include "optional.html" ignore missing %}
=head2 Raw
{% raw %}
{{ this is not rendered }}
{% endraw %}
=head2 With
{% with x = 10, y = 20 %}
{{ x + y }}
{% endwith %}
=head1 BUILT-IN FILTERS
upper Convert to uppercase
lower Convert to lowercase
trim Strip leading/trailing whitespace
length String or list length
reverse Reverse string or list
escape / e HTML-escape (&, <, >, ", ')
safe Mark as safe (skip auto_escape)
default / d Return value or default if undefined/empty
replace Replace substring
truncate Truncate string
join Join list with separator
first First element of list
last Last element of list
list Wrap scalar in list
abs Absolute value
int Convert to integer
float Convert to float
string Convert to string
title Title-case each word
capitalize Capitalize first letter
urlencode Percent-encode URL
wordcount Count words
batch Split list into chunks of N
slice Split list into N slices
sort Sort list (optionally by attribute)
unique Remove duplicates
min Minimum value in list
max Maximum value in list
sum Sum of list
( run in 0.511 second using v1.01-cache-2.11-cpan-71847e10f99 )