Orion API - Django mallbibliotek
Det här dokumentet täcker tagg-, insticksprograms- och filter-API:erna Django Template Library (DTL).
Django 1.0 Taggar
autoescape
Dotiac::DTL::Tag::autoescape - The {% autoescape [on/off] %} tag
SYNOPSIS
Template file:
{% autoescape on %}
This variable will be HTML escaped: {{ "&'\"" }}
{% endautoescape %}
{% autoescape off %}
This variable will NOT be HTML escaped: {{ "&'\"" }}
{% endautoescape %}
DESCRIPTION
Controls the autoescape behavior of an area.
Parameter:
[on/off]
Optional parameter:
on
Autoescaping is on for that whole area till {% endautoescape %}
off
Autoescaping is on for that whole area till {% endautoescape %}
[default]
Defaults to no change at all.
BUGS AND DIFFERENCES TO DJANGO
autoescape in extend without a block
This won't work around blocks in an extend:
{% extend "main.html %}
{% autoescape off %}
{% block content %}
This variable will be HTML escaped: {{ "&'\"" }}, even if there is an autoescape tag setting it off around it.
{% endblock content %}
{% endautoescape %}
If you but the autoescape tags into the block, it will work:
{% extend "main.html %}
{% block content %}
{% autoescape off %}
This variable will NOT be HTML escaped: {{ "&'\"" }}
{% endautoescape %}
{% endblock content %}
SEE ALSO
http://www.djangoproject.com, the Dotiac::DTL manpage
LEGAL
Dotiac::DTL was built according to
http://docs.djangoproject.com/en/dev/ref/templates/builtins/.
AUTHOR
Marc-Sebastian Lucksch
perl@marc-s.de
block
Dotiac::DTL::Tag::block - The {% block NAME %} tag
SYNOPSIS
Template file: (main.html)
<html>
<head>
<title>{% block title %}Default title{% endblock title %}</title>
</head>
<body>
<div class="main">{% block pagecontent %}
This page has no content.
{% endblock %}</div>
</body>
</html>
Other template file: (aboutus.html)
{% extends "main.html" %}
{% block title %}About us{% endblock %}
{% block pagecontent %}<h1>About us</h1>Under construction{% endblock %}
Other template file: (aboutus2.html)
{% extends "main.html" %}
{% block pagecontent %}<h1>About us</h1>Under construction{% endblock %}
DESCRIPTION
The "block" tag defines a named block, which can be overwritten or
overwrites it.
It is normaly used together with {% extends %}. It defines a block in
one template and then overwrites the defined block from another
template. This is called "template inheritance". There are some great
examples on the original Djagno homepage:
http://docs.djangoproject.com/en/dev/topics/templates/#template-inherita
nce
Everything from {% block NAME %} till {% endblock [NAME] %} is treated
as a block with the name NAME. In another template, which contains an {%
extends "abovetemplate" %}, the block NAME can be overwritten.
The previous content of the block can be used in that block via the
variable {{ block.super }}
If no new block with the same name is defined, the default text is used.
If no extend is used, the {% block %} tags will just return their
content.
Of course all variables in a block will work just as they would outside,
even if the block is defined in a different file alltogether.
The above examples will produce:
Rendering just "main.html", the block-tags will disappear:
<html>
<head>
<title>Default title</title>
</head>
<body>
<div class="main">
This page has no content.
</div>
</body>
</html>
Rendering "aboutus.html", all block-tags will be replaced:
<html>
<head>
<title>About us</title>
</head>
<body>
<div class="main"><h1>About us</h1>Under construction</div>
</body>
</html>
Rendering "aboutus2.html", one block-tags will be replaced, the other
will be left as default:
<html>
<head>
<title>Default title</title>
</head>
<body>
<div class="main"><h1>About us</h1>Under construction</div>
</body>
</html>
SEE ALSO
http://www.djangoproject.com, the Dotiac::DTL manpage
BUGS AND DIFFERENCES TO DJANGO
If you find any, please report them.
LEGAL
Dotiac::DTL was built according to
http://docs.djangoproject.com/en/dev/ref/templates/builtins/.
AUTHOR
Marc-Sebastian Lucksch
perl@marc-s.de
comment
Dotiac::DTL::Tag::comment - The {% comment %} tag
SYNOPSIS
Template file:
{% comment %}
This text will never be seen
{% endcomment %}
DESCRIPTION
Ignores everything between {% comment %} and {% endcomment %}.
BUGS AND DIFFERENCES TO DJANGO
The part between {% comment %} and {% endcomment %} still has to be
valid.
Use {# ... #} for another type of comment.
Not really a bug, but everything in this tags will also be compiled to
perl, but optimized away by the perl parser.
SEE ALSO
http://www.djangoproject.com, the Dotiac::DTL manpage
LEGAL
Dotiac::DTL was built according to
http://docs.djangoproject.com/en/dev/ref/templates/builtins/.
AUTHOR
Marc-Sebastian Lucksch
perl@marc-s.de
debug
Dotiac::DTL::Tag::debug - The {% debug %} tag
SYNOPSIS
Template file:
{% debug %}
DESCRIPTION
Prints some debugging information about autoescape status and variables.
BUGS AND DIFFERENCES TO DJANGO
This doesn't work at all like Django's debug, but it provides similar
information.
This tag shouldn't be used in production systems anyways.
SEE ALSO
http://www.djangoproject.com, the Dotiac::DTL manpage
LEGAL
Dotiac::DTL was built according to
http://docs.djangoproject.com/en/dev/ref/templates/builtins/.
AUTHOR
Marc-Sebastian Lucksch
perl@marc-s.de
extends
Dotiac::DTL::Tag::extends - The {% extends FILE %} tag
SYNOPSIS
Template file:
{% extends "main.html" %}
{% block title %}About us{% endblock %}
{% block pagecontent %}<h1>About us</h1>Under construction{% endblock %}
Other template file:
{% extends variable %}
This text will never be printed, ever.
{% block pagecontent %}<h1>Main Page</h1>Under construction{% endblock %}
DESCRIPTION
Loads another template and replaces its content with this.
The content will be ignored, unless {% block %} tags, which are
evaluated. Those will replace the corresponding {% block %} tags in the
included template. See Dotiac::DTL::Tag::block for details
The FILE parameter can be either a string: "file.html" or a variable. If
it is a string, the template will be loaded and parsed during the parse
time of the template, which is faster. A variable can be either a
filename or a Dotiac::DTL object.
BUGS AND DIFFERENCES TO DJANGO
Django's {% extend %} works for the whole files and ends at the file
end. In this Dotiac::DTL, this is also valid and works as you would
expect:
Template file:
<html><body>
{% extends "sidebar.html" %}
{% block sidebartext1 %}Great news{% endblock %}
{% block sidebartext2 %}Dotiac::DTL finished{% endblock %}
{% endextends %}
<div id="page">
Page content
</div>
{% extends "footer.html" %}
{% block foottext %}Author: me{% endblock foo %}
{% endextends %}
</body></html>
Most tags update blocks even if they shouldn't, this is why this won't
work as you expect.
Django doesn't allow this anyway. This will always set the
"content"-block to "No Text" no matter what var is.
{% extends "foo.html" %}
{% if var %}
{% block content %}
Text
{% endblock content %}
{% else %}
{% block content %}
No Text
{% endblock content %}
{% endif %}
SEE ALSO
http://www.djangoproject.com, the Dotiac::DTL manpage
LEGAL
Dotiac::DTL was built according to
http://docs.djangoproject.com/en/dev/ref/templates/builtins/.
AUTHOR
Marc-Sebastian Lucksch
perl@marc-s.de
filter
Dotiac::DTL::Tag::filter - The {% filter
FILTER1[|FILTER2[|FILTER3[|...]]] %} tag
SYNOPSIS
Template file:
{% filter lower %}
HELLO WORLD {% include "other.html" %}
{% endfilter %} {# = hello world ..#}
{% filter striptags|cut:"x" %}
<img src="dirty.png">xxxTheManxxx
{% endfilter %} {# = TheMan #}
DESCRIPTION
Applies a filter to the output of everything between {% filter %} and {%
endfilter %}.
See the Dotiac::DTL::Filter manpage for a list of available filters.
BUGS AND DIFFERENCES TO DJANGO
The tag has to gather all the data first, so it will use remove the
memory benefits coming from using print(), but only for the content
inside the filter.
SEE ALSO
http://www.djangoproject.com, the Dotiac::DTL manpage
LEGAL
Dotiac::DTL was built according to
http://docs.djangoproject.com/en/dev/ref/templates/builtins/.
AUTHOR
Marc-Sebastian Lucksch
perl@marc-s.de
firstof
Dotiac::DTL::Tag::firstof - The {% firstof
VARIABLE1[|VARIABLE2[|VARIABLE3[|...]]] %} tag
SYNOPSIS
Template file:
{% firstof var1 var2 "default text" %}
DESCRIPTION
Outputs the first true value from its argument list.
This is the same as:
{% if var1 %}
{{ var1 }}
{% else %}
{% if var2 %}
{{ var2 }}
{% else %}
default text
{% endif %}
{% endif %}
BUGS AND DIFFERENCES TO DJANGO
If you find one, please report it.
SEE ALSO
http://www.djangoproject.com, the Dotiac::DTL manpage
LEGAL
Dotiac::DTL was built according to
http://docs.djangoproject.com/en/dev/ref/templates/builtins/.
AUTHOR
Marc-Sebastian Lucksch
perl@marc-s.de
for
Dotiac::DTL::Tag::for - The {% for
VARIABLE1[|VARIABLE2[|VARIABLE3[|...]]] in VARIABLE %} tag
SYNOPSIS
Template file:
{% for x in arrayloop %}
{{ forloop.counter }}: {{ x }}
{% endfor %}
{% for x in hashloop %}
{{ forloop.revcounter }}: {{ x }}
{% endfor %}
{% for key,value in hashloop %}
{{key}} is {{ value }}
{% endfor %}
{% for x,y in arrayofarrayloop %}
X = {{ x }}, Y = {{ y }}
{% endfor %}
{% for x in emptyloop %}
{{ forloop.counter }}: {{ x }}
{% empty %}
The loop is empty
{% endfor %}
Perl-file:
$t=Dotiac::DTL->new("page.html");
$t->print(
{
arrayloop=>[1 .. 10],
hashloop=>{A=>1,B=>2,C=>3,D=>4},
arrayofarrayloop=[[1,10],[2,20],[3,30]]
});
DESCRIPTION
Iterates over a datastructure, assigns the variable to every element of
an array or hash and runs the included templatecode with it.
If the loop is empty and an {% empty %} tag is given, it will run the
templatecode from {% empty %} to {% endfor %}.
If given one variable to assign with a hash, it will set it to the
value, if given two, it will assign the key to the first and the value
to the second variable.
If given more than one variable and a array of arrays, it will assagin
the variables to the hash content.
See also
http://docs.djangoproject.com/en/dev/ref/templates/builtins/#for for
more details and examples.
the forloop variable.
Inside a loop, these variables are set:
forloop.counter
The current iteration of the loop, starting with 1.
forloop.counter0
The current iteration of the loop, starting with 0.
forloop.revcounter
The remaining iterations, starting ending with 1.
forloop.revcounter0
The remaining iterations, starting ending with 0.
forloop.first
True if this iteration is the first one.
forloop.last
True if this iteration is the last one.
forloop.parentloop
In nested loops, this is the one above the current
BUGS AND DIFFERENCES TO DJANGO
Also sets forloop.key if iterating over a hash.
SEE ALSO
http://www.djangoproject.com, the Dotiac::DTL manpage
LEGAL
Dotiac::DTL was built according to
http://docs.djangoproject.com/en/dev/ref/templates/builtins/.
AUTHOR
Marc-Sebastian Lucksch
perl@marc-s.de
ifchanged
Dotiac::DTL::Tag::ifchanged - The {% ifchanged [VARIABLE] %} tag
SYNOPSIS
Template file:
{% for x in loop %}
{% ifchanged %}
Posted on {{ x.date }}
{% endifchanged %}
{% ifchanged x.poster %}
Reply by {{ x.poster }} on {{ x.date }}
{% endifchanged %}
{% endfor %}
DESCRIPTION
Without VARIABLE, ifchanged only renders its content, if the content
changed since the last iteration of a loop above.
With VARIABLE, ifchanged only renders its content, if VARIABLE has
changed since the last iteration of a loop above.
Note
Every ifchanged stands on its own, even if they have the same variable
or content to check.
{% ifchanged x.post %}
... {# This will be displayed #}
{% endifchanged %}
{% ifchanged x.post %}
... {# This will also be displayed #}
{% endifchanged %}
BUGS AND DIFFERENCES TO DJANGO
This implementation also supports the {% else %} tag in ifchanged, which
is not included in Django, but there is a patch for that.
{% for timepoint in timepoints %}
{% ifchanged timepoint.day %}
It's a new day.
{% else %}
It's still {{ timepoint.day }}
{% endifchanged %}
{% endfor %}
SEE ALSO
http://www.djangoproject.com, the Dotiac::DTL manpage
LEGAL
Dotiac::DTL was built according to
http://docs.djangoproject.com/en/dev/ref/templates/builtins/.
AUTHOR
Marc-Sebastian Lucksch
perl@marc-s.de
ifequal
Dotiac::DTL::Tag::ifequal - The {% ifequal VARIABLE1 VARIABLE2 %} tag
SYNOPSIS
{% ifequal post.date comment.date %}
At the same time
{% else %}
{{ comment.date|timesice:post.date }} ago
{% endifequal %}
DESCRIPTION
Compoares two variables, and if they are equal, the content is rendered.
If they are not equal and an optional {% else %} block is found, that
block is rendered.
BUGS AND DIFFERENCES TO DJANGO
If given an array or hash, it will only compare the length (like perl
does), since there is no default array or hash comparision (This will
change with perl6)
So you can write:
{% ifequal loop 3 %}
Loop has three elements
{% endifequal %}
But to stay compatible with Django, you should write:
{% ifequal loop|length 3 %}
Loop has three elements
{% endifequal %}
If you want to compare the content, use this:
{% ifequal loop|stringformat:"s" otherloop|stringformat:"s" %}
...
{% endifqual %}
Warning: This might be quite slow, that's why it isn't default.
SEE ALSO
http://www.djangoproject.com, the Dotiac::DTL manpage
LEGAL
Dotiac::DTL was built according to
http://docs.djangoproject.com/en/dev/ref/templates/builtins/.
AUTHOR
Marc-Sebastian Lucksch
perl@marc-s.de
ifnotequal
Dotiac::DTL::Tag::ifnotequal - The {% ifnotequal VARIABLE1 VARIABLE2 %}
tag
SYNOPSIS
{% ifnotequal post.date comment.date %}
{{ comment.date|timesice:post.date }} ago
{% else %}
At the same time
{% endifnotequal %}
DESCRIPTION
Compoares two variables, and if they are NOT equal, the content is
rendered.
If they are not equal and an optional {% else %} block is found, that
block is rendered.
BUGS AND DIFFERENCES TO DJANGO
If given an array or hash, it will only compare the length (like perl
does), since there is no default array or hash comparision (This will
change with perl6)
So you can write:
{% ifnotequal loop 3 %}
Loop has not three elements
{% endifnotequal %}
But to stay compatible with Django, you should write:
{% ifnotequal loop|length 3 %}
Loop has not three elements
{% endifnotequal %}
If you want to compare the content, use this:
{% ifnotequal loop|stringformat:"s" otherloop|stringformat:"s" %}
...
{% endifqual %}
Warning: This might be quite slow, that's why it isn't default.
SEE ALSO
http://www.djangoproject.com, the Dotiac::DTL manpage
LEGAL
Dotiac::DTL was built according to
http://docs.djangoproject.com/en/dev/ref/templates/builtins/.
AUTHOR
Marc-Sebastian Lucksch
perl@marc-s.de
if
Dotiac::DTL::Tag::if - The {% if [not ]VARIABLE1[ or [not ]VARIABLE2[ or
..]]|[and [not ]VARIABLE2[ and ..]] %} tag
SYNOPSIS
Template file:
{% if var %}
var is true
{% endif %}
{% if var %}
var is true
{% else %}
var is not true
{% endif %}
{% if not var %}
var is not true
{% endif %}
{% if not var %}
var is not true
{% else %}
var is true
{% endif %}
{% if var and var2 and not var3 %}
....
{% endif %}
{% if var or not var2 or var3 %}
....
{% endif %}
DESCRIPTION
Conditional rendering of templates, everything between {% if .. %} and
{% else %} or {% endif %} is only rendered if the condition in the if
clause is true.
The part between {% else %} and {% endif %}, if exists, is only rendered
if the condition is false.
The condition
You can link conditions with either "and" or "or", but not both (there
is a problem with precedence), you have to use two {% if %}'s for that.
{% if var1 %}
{% if var2 or var3 %}
This would be the same as "if var1 and (var2 or var3)", if that would work.
{% endif %}
{% endif %}
You can negate a variable in any case with a "not" before it:
{% if not var %}
....
{% endif %}
{% if not var1 and var2 and not var3 %}
...
{% endif %}
{% if not var1 or var2 or not var3 %}
...
{% endif %}
False values
False is:
0 # The number 0
0.00 # The number 0.0
"" # An empty string
"0" # A string containing a null
undef # A null value
{} # An empty hash
[] # An empty list/array
An unknown variable, even if $Dotiac::DTL::TEMPLATE_STRING_IF_INVALID is set to something true.
not "a true value" # not negates true to false and false to true.
True values
Everything else is true, including references to objects which are false
and references to empty strings.
SEE ALSO
http://www.djangoproject.com, the Dotiac::DTL manpage
BUGS AND DIFFERENCES TO DJANGO
If you find any, please report them
LEGAL
Dotiac::DTL was built according to
http://docs.djangoproject.com/en/dev/ref/templates/builtins/.
AUTHOR
Marc-Sebastian Lucksch
perl@marc-s.de
include
Dotiac::DTL::Tag::include - The {% include FILE %} tag
SYNOPSIS
Template file:
{% include variable %} {# for example, monday.html, tuesday.html everyday another header #}
<div id="content"> ... </div>
{% include "footer.html" %}
</body>
</html>
Included template file (footer.html):
<div id="footer">{{ Footertext }}</div>
DESCRIPTION
Loads another template and renders the content in at the point where the
tag is standing. All variables are given to the included template as
well, so they can be used in there.
The FILE parameter can be either a string: "file.html" or a variable. If
it is a string, the template will be loaded and parsed during the parse
time of the template, which is faster. A variable can be either a
filename or a Dotiac::DTL object.
BUGS AND DIFFERENCES TO DJANGO
If you find any, please let me know
SEE ALSO
http://www.djangoproject.com, the Dotiac::DTL manpage
LEGAL
Dotiac::DTL was built according to
http://docs.djangoproject.com/en/dev/ref/templates/builtins/.
AUTHOR
Marc-Sebastian Lucksch
perl@marc-s.de
load
Dotiac::DTL::Tag::load - The {% load NAME %} tag
SYNOPSIS
Template file:
{% load markup %}
{{ post.text|markdown }}
DESCRIPTION
Loads a library with a specific NAME, which may contain additional
filters, tags or custom locale stettings. See the Dotiac::DTL::Addon
manpage for details.
BUGS AND DIFFERENCES TO DJANGO
This can't work at all like Django's {% load %}, since that one requires
python. This implementation requires "Dotiac::DTL::Addon::$NAME", with
all non-word characters in $NAME replace with underlines "_". It then
calls the import() method of that module. See also the
Dotiac::DTL::Addon manpage for that.
Example:
{% load Foo.bar+this %}
tries to require Django/Template/Addon/Foo_bar_this.pm and calls
Dotiac::DTL::Foo_bar_this->import().
After the rendering is completed, Dotiac::DTL::Foo_bar_this->unimport()
is called before the next render process.
Warning
Dotiac::DTL keeps the loaded locales and loaded addons active even after
an include.
common.html:
{% load addon1 addon2 addon3 klingon_locale %}
page.html:
{% include "common.html" %}
{{ a|addon1 }} {# This won't work in Django #}
SEE ALSO
http://www.djangoproject.com, the Dotiac::DTL manpage
LEGAL
Dotiac::DTL was built according to
http://docs.djangoproject.com/en/dev/ref/templates/builtins/.
AUTHOR
Marc-Sebastian Lucksch
perl@marc-s.de
now
Dotiac::DTL::Tag::now - The {% now FORMAT %} tag
SYNOPSIS
Template file:
{% now "d. o\f F Y \a\t P %} {# 03. of May 1999 at 12:30 a.m. #}
DESCRIPTION
Gives the current time and a specific FORMAT to the date filter (See L<Dotiac::DTL::Filter>). This will result in the current time being formatted according to the specified FORMAT.
Format options
You can combine as many of these as you like or need:
{% now "d. b." %}
"\" Returns the next character, regardless if it is a format character
or not.
{% now "\H\e\l\l\o \W\o\r\l\d" %} {# =Hello World #}
This also means "\n" will in this case render an "n" and NOT a
newline. Same for "\t","\f","\b","\r".
"a" Returns whether it is AM or PM in Associated Press style: "a.m." or
"p.m".
{% now "a" %} {# a.m. on in the morning#}
This might change if a locale module is loaded.
"A" Returns AM or PM.
{% now "A" %} {# AM #}
This might change if a locale module is loaded.
"b" Returns the current month in 3 lowercase letters.
{% now "b" %} {# dec #}
This might change if a locale module is loaded.
"d" Returns the day of the month with a leading zero.
{% now "d" %} {# 01 #} to {# 31 #}
"D" Returns the day of the week in 3 letters (2 letters on some locales)
{% now "D" %} {# Sun #}
This might change if a locale module is loaded.
"f" Returns the time with hours and minutes, but minutes are left out if
they are 0.
{% now "f" %} o'clock {# 11:30 o'clock #} {# 3 o'clock #}
"F" Returns the month in long form.
{% now "F" %} {# December #}
This might change if a locale module is loaded.
"g" Returns the hour in 12-hour format without leading zeros.
{% now "g" %} {# 1 #} to {# 12 #}
"G" Returns the hour in 24-hour format without leading zeros.
{% now "G" %} {# 0 #} to {# 24 #}
"h" Returns the hour in 12-hour format with a leading zero.
{% now "h" %} {# 01 #} to {# 12 #}
"H" Returns the hour in 24-hour format with a leading zero.
{% now "H" %} {# 00 #} to {# 24 #}
"i" Returns the minutes with a leading zero.
{% now "i" %} {# 00 #} to {# 60 #}
"j" Returns the day of the month without leading zeros.
{% now "j" %} {# 1 #} to {# 31 #}
"l" Returns the day of the week as a long text.
{% now "l" %} {# Sunday #}
This might change if a locale module is loaded.
"L" Returns 1 or 0 whether it's a leap year.
{% now "L" %} {# 1 #}
*Not that needed with now, but with the date filter*
"m" Returns the current month as a number with leading zeros.
{% now "m" %} {# 01 #} to {# 12 #}
"M" Returns the current month in 3 letters.
{% now "M" %} {# Dec #}
This might change if a locale module is loaded.
"n" Returns the current month as a number without leading zeros.
{% now "m" %} {# 1 #} to {# 12 #}
"M" Returns the current in Associated Press style notation.
{% now "M" %} {# Jan. #} {# March #} {# July #}
This might change if a locale module is loaded.
"O" Returns the difference to Greenwich time in hours.
{% now "O" %} {# +0100 #}
"P" Returns either the time in 12 hours and minutes if not zero with
a.m. or p.m., midnight or noon.
{% now "P" %} {# 1 p.m. #} {# 11:56 a.m. #} {# midnight #} {# noon #}
"r" Returns an RFC 2822 formatted date.
{% now "r" %} {# Sun, 28 Dec 2008 18:36:24 +0200' #}
This might change if a locale module is loaded.
"s" Returns the seconds with a leading zero.
{% now "s" %} {# 00 #} to {# 59 #}
"S" Returns the ordinal suffix for the day of the month.
{% now "S" %} {# st #} {# nd #} {# rd #} {# th #}
Defaults to english, this may change if a locale module is loaded.
"t" Returns the number of days in the given month.
{% now "t" %} {# 28 #} to {# 31 #}
"T" Returns the current timezone (needs the POSIX module)
{% now "T" %} {# CET #} {# GMT #} {# EST #}...
"w" Returns the day of week as a number from 0 (Sunday) to 6 (Saturday)
{% now "w" %} {# 1 #} to {# 6 #}
"W" Returns the ISO-8601 week number of year (uses the POSIX module),
weeks start on monday.
{% now "w" %} {# 1 #} to {# 53 #}
"y" Returns the year in two digits (with leading zeros)
{% now "y" %} {# 08 #}
"Y" Returns the year in four (or more) digits (with leading zeros)
{% now "Y" %} {# 2008 #}
"z" Returns the day of the year without leading zeros
{% now "z" %} {# 0 #} to {# 365 #}
"Z" Returns the difference of the current timezone to GMT in seconds.
{% now "Z" %} {# -43200 #} to {# 43200 #}
BUGS AND DIFFERENCES TO DJANGO
If you find any, please inform me about them.
SEE ALSO
http://www.djangoproject.com, the Dotiac::DTL manpage
LEGAL
Dotiac::DTL was built according to
http://docs.djangoproject.com/en/dev/ref/templates/builtins/.
AUTHOR
Marc-Sebastian Lucksch
perl@marc-s.de
regroup
Dotiac::DTL::Tag::regroup - The {% regroup LIST by PROPERTY as
NEWVARIABLE %} tag
SYNOPSIS
Template file:
{% regroup loop by gender as grouped %}
{% for group in grouped %}
<h1>{{ group.grouper }}</h1>
{% for entry in group.list %}
<p>{{ entry }}</p>
{% endfor %}
{% endfor %}
DESCRIPTION
Regroups a LIST of objects, hashes or list by a common PROPERTY and
saves it into a NEW VARIABLE.
The resulting NEW VARIABLE is a list containing hashes with a "grouper"
string, containing the text which was grouped by and a "list" which
contains all the objects with the same "grouper" string
This is best explained with an example. If you have this datastructure,
each a blog post with a category:
Posts=>[
{title=>"I love food",text=>"I really do",category=>"My life"},
{title=>"I love TV",text=>"Even more than food",category=>"My life"},
{title=>"Simpsons",text=>"Awesome TV show",category=>"TV shows"},
{title=>"ANTM",text=>"I love this one",category=>"TV shows"},
{title=>"xkcd",text=>"The best webcomic",category=>"Webcomics"}
]
Now you want to group it by that "category" in the template:
{% regroup Posts by category as posts_grouped %}
{% for cat in posts_grouped %}
<h1>Category: {{ cat.grouper }}</h1>
{% for entry in cat.list %}
<h2>{{ entry.title }}</h2>
{{ entry.text|linebreaks }}
{% endfor %}
{% endfor %}
This will result in this rendered template:
<h1>Category: My life</h1>
<h2>I love food</h2>
<p>I really do</p>
<h2>I love TV</h2>
<p>Even more than food</p>
<h1>Category: TV shows</h1>
<h2>Simpsons</h2>
<p>Awesome TV show</p>
<h2>ANTM</h2>
<p>I love this one</p>
<h1>Category: Webcomics</h1>
<h2>xkcd</h2>
<p>The best webcomic</p>
Django has another fine example for this:
http://docs.djangoproject.com/en/dev/ref/templates/builtins/#regroup
BUGS AND DIFFERENCES TO DJANGO
Django's regroup tag needs the LIST to be sorted, this implementation
doesn't need it.
I don't know about Django, but here PROPERY can also contain filters.
{% regroup loop by content|length as grouped %}
SEE ALSO
http://www.djangoproject.com, the Dotiac::DTL manpage
LEGAL
Dotiac::DTL was built according to
http://docs.djangoproject.com/en/dev/ref/templates/builtins/.
AUTHOR
Marc-Sebastian Lucksch
perl@marc-s.de
spaceless
Dotiac::DTL::Tag::spaceless - The {% spaceless %} tag
SYNOPSIS
Template file:
{% spaceless lower %}
<body>
<p>
<br>
</p>
Text
</body>
{% endspaceless %} {# = hello world ..#}
This will result in:
<body> <p> <br> </p>
Text
</body>
DESCRIPTION
Reduces all the spaces between tags in the output to a single space. The
spaces between tags and text or text and text are left as they are.
BUGS AND DIFFERENCES TO DJANGO
The tag has to gather all the data first, so it will use remove the
memory benefits coming from using print(), but only for the content
inside the block.
SEE ALSO
http://www.djangoproject.com, the Dotiac::DTL manpage
LEGAL
Dotiac::DTL was built according to
http://docs.djangoproject.com/en/dev/ref/templates/builtins/.
AUTHOR
Marc-Sebastian Lucksch
perl@marc-s.de
ssi
Dotiac::DTL::Tag::ssi - The {% ssi FILE [parsed] %} tag
SYNOPSIS
Template file:
Some text {% ssi "/home/foo/web/index.html" %}
Some other text {% ssi "/home/foo/web/djangoindex.html" parsed %}
DESCRIPTION
Similar to the {% include %} (the Dotiac::DTL::Tag::include manpage)
tag, but includes FILEs to be included from anywhere in the filesystem.
So this tag will only work if $Dotiac::DTL::ALLOWED_INCLUDE_ROOTS is set
to true (See the Dotiac::DTL::Core manpage).
If there is a "parsed" at the end of the tag the file is treated as a
template. (like {% include %}) If it isn't there, just the text is
included, no matter what is in there.
BUGS AND DIFFERENCES TO DJANGO
The ssi-tag can't work with template objects, there is no need, use the
include-tag for that.
If you find any, please let me know.
SEE ALSO
http://www.djangoproject.com, the Dotiac::DTL manpage
LEGAL
Dotiac::DTL was built according to
http://docs.djangoproject.com/en/dev/ref/templates/builtins/.
AUTHOR
Marc-Sebastian Lucksch
perl@marc-s.de
templatetag
Dotiac::DTL::Tag::templatetag - The {% templatetag
openblock|closeblock|openvariable|closevariable|openbrace|closebrace|ope
ncomment|closecomment %} tag
SYNOPSIS
Template file:
{% templatetag openblock %} templatetag {% templatetag closeblock %}
{% templatetag openvariable %} var1 {% templatetag closevariable %}
{% templatetag openbrace %} somebrace {% templatetag closebrace %}
{% templatetag opencomment %} no comment {% templatetag closecomment %}
This will result in:
{% templatetag %}
{{ var1 }}
{ somebrace }
{# no comment #}
DESCRIPTION
Inserts the special tags used by Django Templates into the rendered
output.
The tags
These are the tags which can be used.
openblock
The tag that opens a tag.
{%
closeblock
The tag that closes a tag.
%}
openvariable
The tag that opens a variable.
{{
closevariable
The tag that closes a variable.
}}
openbrace
This is not needed in this implementation, since you can include
braces in the template, if they are not followed by another {, % or
#.
{
closebrace
Also not needed in this implementation.
}
opencomment
The tag that starts a comment.
{%
closecomment
The tag that ends a comment.
%}
BUGS AND DIFFERENCES TO DJANGO
If you find any, please let me know.
SEE ALSO
http://www.djangoproject.com, the Dotiac::DTL manpage
LEGAL
Dotiac::DTL was built according to
http://docs.djangoproject.com/en/dev/ref/templates/builtins/.
AUTHOR
Marc-Sebastian Lucksch
perl@marc-s.de
url
Dotiac::DTL::Tag::url - The {% url
PATH,[PATH,[...],[PARAMETER=VALUE,[PARAMETER=VALUE,[..]]] [as VAR] %}
tag
SYNOPSIS
Template file:
{% url "forum","thread",variable,"id"=post.id %} {# forum/thread/444/?id=556 #}
{% url "","forum","thread",variable,"id"=post.id %} {# /forum/thread/444/?id=556 #}
{% url "http://www.google.com","forum","thread",variable,"id"=post.id %} {# http://www.google.com/forum/thread/444/?id=556 #}
{% url "http://www.google.com","forum","thread",variable,"id"=post.id as link_url %} {# <nothing> #}
{{ link_url|upper|safe }} {# HTTP://WWW.GOOGLE.COM/FORUM/THREAD/444/?ID=556 #}
DESCRIPTION
Generates an url from a joined PATH and adds also PARAMETERs with VALUES
for get-queries.
When provided with an "as" and a variable name, it will output nothing
and save the url into a variable, which can be used for further
processing.
the PATH, PARAMETERs and VALUES are automatically url-encoded.
BUGS AND DIFFERENCES TO DJANGO
The normal Django {% url %} tag gets as a first parameter the name of
Django-view, since there is no Django backend in this implementation,
this is not possible.
When writing the url into a variable, that variable has to be marked
safe manually, using the safe Filter (See the Dotiac::DTL::Filter
manpage)
SEE ALSO
http://www.djangoproject.com, the Dotiac::DTL manpage
LEGAL
Dotiac::DTL was built according to
http://docs.djangoproject.com/en/dev/ref/templates/builtins/.
AUTHOR
Marc-Sebastian Lucksch
perl@marc-s.de
widthratio
Dotiac::DTL::Tag::widthratio - The {% widthratio CURRENTVALUE MAXVALUE
CONSTANT %} tag
SYNOPSIS
Template file:
<img src="bar.png" width="{% widthratio current max 160 %}">
DESCRIPTION
Calculates the ratio of CURRENTVALUE to MAXVALUE and applies this to a
CONSTANT.
CURRENTVALUE and MAXVALUES are variables and CONSTANT is a constant
number.
This is useful if you want to create a bar for the progress of a
multi-page form: CURRENVALUE is the current page, MAXVALUE is the total
number of pages a user has to fill out. CONSTANT is then the size of the
bar at a 100%, for example 160 for a 160px bar.
BUGS AND DIFFERENCES TO DJANGO
If you find any, please let me know.
SEE ALSO
http://www.djangoproject.com, the Dotiac::DTL manpage
LEGAL
Dotiac::DTL was built according to
http://docs.djangoproject.com/en/dev/ref/templates/builtins/.
AUTHOR
Marc-Sebastian Lucksch
perl@marc-s.de
Django Laddade Plugins
markup
Dotiac::DTL::Addon::markup: Filters to work with common markup languages
SYNOPSIS
Load from a Dotiac::DTL-template:
{% load markup %}
Load in Perl file for all templates:
use Dotiac::DTL::Addon::markup;
Then it can be used:
{{ var|markdown }}
{{ text|textile }}
{{ content|restructuredtext }}
INSTALLATION
via CPAN:
perl -MCPAN -e "install Dotiac::DTL::Addon::markup"
or get it from
https://sourceforge.net/project/showfiles.php?group_id=249411&package_id
=306751, extract it and then run in the extracted folder:
perl Makefile.PL
make test
make install
DESCRIPTION
This is like Django.contrib.markup,
(http://docs.djangoproject.com/en/dev/ref/contrib/#ref-contrib-marku),
but for Dotiac::DTL and Perl.
It converts some of the common markup languages to HTML.
Filters
textile
Converts textile syntax to HTML.
Gives the content to Text::Textile and returns the results.
It will always return a safe string.
my $text = <<EOT;
h1. Heading
A _simple_ demonstration of Textile markup.
* One
* Two
* Three
"More information":http://www.textism.com/tools/textile is available.
EOT
text=>$text;
In the template:
{{ text|textile }}
This will render to:
<h1>Heading</h1>
<p>A <em>simple</em> demonstration of Textile markup.</p>
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
<p><a href="http://www.textism.com/tools/textile">More information</a> is available.</p>
Example from the Text::Textile manpage.
markdown
Converts markdown syntax to HTML.
Gives the content to Text::Markdown and returns the results.
It will always return a safe string.
my $text = <<EOM;
A First Level Header
====================
A Second Level Header
---------------------
Now is the time for all good men to come to
the aid of their country. This is just a
regular paragraph.
The quick brown fox jumped over the lazy
dog's back.
### Header 3
> This is a blockquote.
>
> This is the second paragraph in the blockquote.
>
> ## This is an H2 in a blockquote
EOM
text=>$text;
In the template:
{{ text|markdown }}
This will render to:
<h1>A First Level Header</h1>
<h2>A Second Level Header</h2>
<p>Now is the time for all good men to come to
the aid of their country. This is just a
regular paragraph.</p>
<p>The quick brown fox jumped over the lazy
dog's back.</p>
<h3>Header 3</h3>
<blockquote>
<p>This is a blockquote.</p>
<p>This is the second paragraph in the blockquote.</p>
<h2>This is an H2 in a blockquote</h2>
</blockquote>
Example from http://daringfireball.net/projects/markdown/basics
restructuredtext
Converts ReST syntax to HTML.
Gives the content to Text::Restructured and returns the results.
It will always return a safe string.
my $text = <<EOR;
=====
Title
=====
Subtitle
--------
Titles are underlined (or over-
and underlined) with a printing
nonalphanumeric 7-bit ASCII
character.
- This is item 1
- This is item 2
EOR
text=>$text;
In the template:
{{ text|markdown }}
This will render to:
<font size="+2"><strong>Title</strong></font>
<p><font size="+1"><strong>Subtitle</strong></font>
</p><p>Titles are underlined (or over-
and underlined) with a printing
nonalphanumeric 7-bit ASCII
character.</p>
<ul>
<li>This is item 1
</li><li>This is item 2
</li></ul>
Example from http://docutils.sourceforge.net/docs/user/rst/quickref.html
BUGS
Since Text::Restructured won't compile under Win32, this can't be
tested. Either it works or it won't.
Please report any bugs or feature requests to
https://sourceforge.net/tracker2/?group_id=249411&atid=1126445
SEE ALSO
the Dotiac::DTL manpage, the Dotiac::DTL::Addon manpage,
http://www.dotiac.com, http://www.djangoproject.com
AUTHOR
Marc-Sebastian Lucksch
perl@marc-s.de
json
Dotiac::DTL::Addon::json: Filters to generate JSON data
SYNOPSIS
Load from a Dotiac::DTL-template:
{% load json %}
Load in Perl file for all templates:
use Dotiac::DTL::Addon::json;
Then it can be used:
{{ data|json|safe }}
{{ data|json_ascii }}
{{ data|json_pretty }}
{{ data|json_pretty_ascii|safe }}
INSTALLATION
via CPAN:
perl -MCPAN -e "install Dotiac::DTL::Addon::json"
or get it from
https://sourceforge.net/project/showfiles.php?group_id=249411&package_id
=306751, extract it and then run in the extracted folder:
perl Makefile.PL
make test
make install
DESCRIPTION
This provides some filters to output any type of data
Filters
Like most other filters, these will return a safe value on safe input.
But string literals are always safe and will produce bad output, so
beware of those.
{{ "Foo"|json }} {# "Foo" #}
{{ "Foo"|json|escape }} {# "Foo" #}
json
Converts any value into JSON, even lists and dictionaries.
Output will be in UTF-8.
data=>{List=>[1,2,3],Value=>"Foo\x{34fc}"};
<a onclick="return {{ data|json }}">
{# <a onclick="return {"List":[1,2,3],"Value":"Foo+"}"> #}
var Value={{ data|json|safe }}
{# var Value={"List":[1,2,3],"Value":"Foo"} #}
json_ascii
Like json, but the output will be in ascii. This is useful if the
generated HTML page is not utf8.
data=>{List=>[1,2,3],Value=>"Foo"};
<a onclick="return {{ data|json_ascii }}">
{# <a onclick="return {"List":[1,2,3],"Value":"Foo\u34fc"}"> #}
var Value={{ data|json_ascii|safe }}
{# var Value={"List":[1,2,3],"Value":"Foo\u34fc"} #}
json_pretty
Like json, but with pretty output. This is much larger and mostly not
needed.
data=>{List=>[1,2,3],Value=>"Foo"};
<a onclick="return {{ data|json_pretty }}">
{# <a onclick="return {
"List" : [
1,
2,
3
],
"Value" : "Foo+"
}"> #}
var Value={{ data|json_pretty|safe }}
{# var Value={
"List" : [
1,
2,
3
],
"Value" : "Fo+"
} #}
json_ascii_pretty
Like json_ascii, but also with pretty output. This is much larger and
mostly not needed.
data=>{List=>[1,2,3],Value=>"Foo"};
<a onclick="return {{ data|json_ascii_pretty }}">
{# <a onclick="return {
"List" : [
1,
2,
3
],
"Value" : "Foo\u34fc"
}"> #}
var Value={{ data|json_ascii_pretty|safe }}
{# var Value={
"List" : [
1,
2,
3
],
"Value" : "Foo\u34fc"
} #}
BUGS
Please report any bugs or feature requests to
https://sourceforge.net/tracker2/?group_id=249411&atid=1126445
SEE ALSO
the Dotiac::DTL manpage, the Dotiac::DTL::Addon manpage,
http://www.dotiac.com, http://www.djangoproject.com
AUTHOR
Marc-Sebastian Lucksch
perl@marc-s.de
Django 1.0 Filter API
Dotiac::DTL::Filter - Filters for variables
SYNOPSIS
{{ variable|add:10|upper }}
{% cycle variable|add:10|upper variable2|add:10|upper %}
{% include "foo.html"|cut:"o"|upper %}
...
DESCRIPTION
Filters are small functions that are applied on variables. They can be
stacked by using a pipe character ( | ), without space. And they have
arguments, denoted by a ":".
Some filters don't require arguments, some have optional ones and other
require then.
If a filter can't use an argument or variable, it will just return it
unchanged.
In this implementation, you can also apply variables as arguments to any
filter and even have multiple arguments for your own filters (seperated
by a ","). However this may cause trouble in some tags (like {% url %})
and is not compatible to Django. Just know it's there if you need it.
Examples:
{{ var|upper }}
Runs the "upper" filter on the content of the variable "var"
{{ var|add:"10" }}
Adds a 10 to the content of the variable "var". the "10" is the argument
(also called parameter) to the "add" filter.
{{ var|upper|add:"foo" }}
This construct runs the "upper" filter on the content of the variable
"var" and then adds the string "foo" to the result of that.
{{ foo|add:bar }}
In this implementation: adds the content of the variable "bar" to
content of the variable "foo".
These are the filters you can use:
add :VALUE
Adds a VALUE (number or string) to the variable.
If both variable and the argument are both numbers, they are added
together.
If one or both of them are not numbers, the arguments are concatenated
together.
{{ "10"|add:"10" }} {# 20 #}
{{ "10"|add:"-5" }} {# 5 #}
{{ "10"|add:"foo" }} {# 10foo #}
{{ "foo"|add:"bar" }} {# foobar #}
{{ "bar"|add:100 }} {# 100 #}
{% filter add:100 %}1{{ "10"|add:"20"}}{% endfilter %} {# 230 #} {# 100+1.(10+20) #}
Bugs and Differences to Django
Django only supports numbers to be added (and substracted).
addslashes
Adds backslashes before any quotes in the variable. This is useful for
CSV output
If you want some more
{{ 'Daimos "TheKing" Miller / Peter \'TheMan\' Miller'|addslashes }} {# Daimos \"TheKing\" Miller \\ Peter \'TheMan\' Miller #}
Bugs and Differences to Django
If you find any, please report them.
capfirst
Converts the first character of the value to an uppercase. Also see
upper() and lower()
{{"foo"|capfirst}} {# Foo #}
{{"bar"|capfirst}} {# Bar #}
{{"foo bar"|capfirst}} {# Foo bar #}
Bugs and Differences to Django
If you find any, please report them.
center :FIELDWIDTH
Centers a text in a field of FIELDWIDTH spaces.
This is not usefull for HTML (unless in <pre> like tags), but for
email's from forms or other text files.
{{ "Hello"|center:"20" }} {# " Hello " #}
The string is not truncated if it's larger than FIELDWIDTH
Bugs and Differences to Django
Also supports a padding parameter, if you want something other than
spaces:
{{ "Hello":center:"20";"-" }} {# "-------Hello--------" #}
cut :STRING
Removes any occurences of a STRING from the value.
{{ "Hello World"|cut:"el" }} {# Hlo World #}
{{ "Hello World"|cut:"l" }} {# Heo Word #}
Bugs and Differences to Django
If you find any, please report them.
date :FORMAT
Formats a time, according to a FORMAT according to a FORMAT..
{{ "20002312"|date:"jS F Y H:i" }} {# 20th August 1970 14:11 #}
{{ post.time|date:"jS o\f F" }} {# It is the 4th of September #}
The retured value will be safe if the FORMAT string is safe.
Format options
You can combine as many of these as you like or need:
{{ var|date:"d. b." }}
"\" Returns the next character, regardless if it is a format character
or not.
{{ var|date: "\H\e\l\l\o \W\o\r\l\d" }} {# =Hello World #}
This also means "\n" will in this case render an "n" and NOT a
newline. Same for "\t","\f","\b","\r".
"a" Returns whether it is AM or PM in Associated Press style: "a.m." or
"p.m".
{{ var|date: "a" }} {# a.m. on in the morning#}
This might change if a locale module is loaded.
"A" Returns AM or PM.
{{ var|date: "A" }} {# AM #}
This might change if a locale module is loaded.
"b" Returns the current month in 3 lowercase letters.
{{ var|date: "b" }} {# dec #}
This might change if a locale module is loaded.
"d" Returns the day of the month with a leading zero.
{{ var|date: "d" }} {# 01 #} to {# 31 #}
"D" Returns the day of the week in 3 letters (2 letters on some locales)
{{ var|date: "D" }} {# Sun #}
This might change if a locale module is loaded.
"f" Returns the time with hours and minutes, but minutes are left out if
they are 0.
{{ var|date: "f" }} o'clock {# 11:30 o'clock #} {# 3 o'clock #}
"F" Returns the month in long form.
{{ var|date: "F" }} {# December #}
This might change if a locale module is loaded.
"g" Returns the hour in 12-hour format without leading zeros.
{{ var|date: "g" }} {# 1 #} to {# 12 #}
"G" Returns the hour in 24-hour format without leading zeros.
{{ var|date: "G" }} {# 0 #} to {# 24 #}
"h" Returns the hour in 12-hour format with a leading zero.
{{ var|date: "h" }} {# 01 #} to {# 12 #}
"H" Returns the hour in 24-hour format with a leading zero.
{{ var|date: "H" }} {# 00 #} to {# 24 #}
"i" Returns the minutes with a leading zero.
{{ var|date: "i" }} {# 00 #} to {# 60 #}
"j" Returns the day of the month without leading zeros.
{{ var|date: "j" }} {# 1 #} to {# 31 #}
"l" Returns the day of the week as a long text.
{{ var|date: "l" }} {# Sunday #}
This might change if a locale module is loaded.
"L" Returns 1 or 0 whether it's a leap year.
{{ var|date: "L" }} {# 1 #}
"m" Returns the current month as a number with leading zeros.
{{ var|date: "m" }} {# 01 #} to {# 12 #}
"M" Returns the current month in 3 letters.
{{ var|date: "M" }} {# Dec #}
This might change if a locale module is loaded.
"n" Returns the current month as a number without leading zeros.
{{ var|date: "m" }} {# 1 #} to {# 12 #}
"M" Returns the current in Associated Press style notation.
{{ var|date: "M" }} {# Jan. #} {# March #} {# July #}
This might change if a locale module is loaded.
"O" Returns the difference to Greenwich time in hours.
{{ var|date: "O" }} {# +0100 #}
"P" Returns either the time in 12 hours and minutes if not zero with
a.m. or p.m., midnight or noon.
{{ var|date: "P" }} {# 1 p.m. #} {# 11:56 a.m. #} {# midnight #} {# noon #}
"r" Returns an RFC 2822 formatted date.
{{ var|date: "r" }} {# Sun, 28 Dec 2008 18:36:24 +0200' #}
This might change if a locale module is loaded.
"s" Returns the seconds with a leading zero.
{{ var|date: "s" }} {# 00 #} to {# 59 #}
"S" Returns the ordinal suffix for the day of the month.
{{ var|date: "S" }} {# st #} {# nd #} {# rd #} {# th #}
Defaults to english, this may change if a locale module is loaded.
"t" Returns the number of days in the given month.
{{ var|date: "t" }} {# 28 #} to {# 31 #}
"T" Returns the current timezone (needs the POSIX module)
{{ var|date: "T" }} {# CET #} {# GMT #} {# EST #}...
"w" Returns the day of week as a number from 0 (Sunday) to 6 (Saturday)
{{ var|date: "w" }} {# 1 #} to {# 6 #}
"W" Returns the ISO-8601 week number of year (uses the POSIX module),
weeks start on monday.
{{ var|date: "w" }} {# 1 #} to {# 53 #}
"y" Returns the year in two digits (with leading zeros)
{{ var|date: "y" }} {# 08 #}
"Y" Returns the year in four (or more) digits (with leading zeros)
{{ var|date: "Y" }} {# 2008 #}
"z" Returns the day of the year without leading zeros
{{ var|date: "z" }} {# 0 #} to {# 365 #}
"Z" Returns the difference of the current timezone to GMT in seconds.
{{ var|date: "Z" }} {# -43200 #} to {# 43200 #}
Bugs and Differences to Django
Since Perl has no default DateTime Object, this expects a normal unix
timestamp ( result of the time() call in perl).
It also excepts the result of localtime as an array reference, this is
useful for timestamps > 2038 on 32-Bit machines.
var=>[36,31,21,2,0,109,5,1,0];
{{ var|date:"jS F Y H:i" }} {# 2nd January 2009 21:31 #}
default :STRING
If the value is false (See the Dotiac::DTL::Tag::if manpage) it will
return the STRING, otherwise the value.
{{ "Hello World"|cut:"el" }} {# Hlo World #}
{{ "Hello World"|cut:"l" }} {# Heo Word #}
Bugs and Differences to Django
Perl considers other things false as Python.
default_if_none :STRING
If the value is not defined (not found or set to `undef') it will return
the STRING, otherwise the value.
{{ "Hello World"|cut:"el" }} {# Hlo World #}
{{ "Hello World"|cut:"l" }} {# Heo Word #}
Bugs and Differences to Django
Perl considers other things false as Python.
dictsort :PROPERTY
Sorts an array of hashes, objects or arrays by a common PROPERTY. (See
`|dictsort' for reverse sort)
Posts=>[
{title=>"I love food",text=>"I really do",category=>"My life"},
{title=>"I love TV",text=>"Even more than food",category=>"My life"},
{title=>"Simpsons",text=>"Awesome TV show",category=>"TV shows"},
{title=>"ANTM",text=>"I love this one",category=>"TV shows"},
{title=>"xkcd",text=>"The best webcomic",category=>"Webcomics"}
]
{% for x in Posts|dictsort:"category" %}...
{% endfor %}
{% for x in Posts|dictsort:"title" %}...
{% endfor %}
Bugs and Differences to Django
If PROPERTY is omitted, it just sorts by name, you can use this to sort
an array of strings.
ListofWords=>["Foo","Bar","Baz"]
{% for x in Posts|dictsort %}
{{x}}
{% endfor %}
dictsortreversed :PROPERTY
Sorts an array of hashes, objects or arrays by a common PROPERTY in
reverse order. (See `|dictsort' for normal order)
Posts=>[
{title=>"I love food",text=>"I really do",category=>"My life"},
{title=>"I love TV",text=>"Even more than food",category=>"My life"},
{title=>"Simpsons",text=>"Awesome TV show",category=>"TV shows"},
{title=>"ANTM",text=>"I love this one",category=>"TV shows"},
{title=>"xkcd",text=>"The best webcomic",category=>"Webcomics"}
]
{% for x in Posts|dictsort:"category" %}...
{% endfor %}
{% for x in Posts|dictsort:"title" %}...
{% endfor %}
Bugs and Differences to Django
If PROPERTY is omitted, it just sorts by name, you can use this to sort
an array of strings.
ListofWords=>["Foo","Bar","Baz"]
{% for x in Posts|dictsort %}
{{x}}
{% endfor %}
divisibleby :NUMBER
Returns 1 (true value) if the value is divisible by NUMBER.
{{ "21"|divisibleby:"7" }} {# 1 #}
{{ "45"|divisibleby:"8" }} {# 0 #}
Bugs and Differences to Django
Django's divisibleby returns a `True' or `False'. There is no binary
type in perl, so it will return `1' or `0'
escape
Marks a string as unsafe, i.e. in need of escaping for output.
` < ', `>', `'', `"' and `&' are converted to `<', `>', `'',
`"' and `&' respectively.
Beware: Escaping is done only once and only after all filters are
applied. If you want to esacpe at this position in the filter pipeline
use `force_escape'.
{{ "<>"|escape }} {# <> #}
{{ "<>"|escape|cut:"&"|escape }} {# <> #} {# Escaping is done only once after all filter are applied #}
{{ "<>"|force_escape|cut:"&"|escape }} {# lt;gt; #} {# This might be what you want. #}
Bugs and Differences to Django
If you find any, please report them.
escapejs
Escapes a Javascript (JSON) String. This will not generate JSON Code out
of datastructures, use the Dotiac::DTL::Addon::JSON manpage for that.
<script>var="{{ "\""|escapejs|safe }}"</script> {# <script>var="\""</script> #} {# you will have to mark it as safe if you are generating in script tags #}
<body onload="alert('{{ "\""|escapejs|escape }}')"> {# <body onload="alert('\"')" #} {# Better escape in event handlers#}
Bugs and Differences to Django
Might escape some more characters than original Django.
On perl 5.6.2 unicode output is not really supported, you will get for
example:
\u00e3\u0093\u00b4 instead of \u4532
filesizeformat
Returns a number of bytes in bytes, Kb, Mb, Gb or Tb ... This is used to
display the size of files/traffic or anything else counted this way to
be read by humans
{{ "3939232"|filesizeformat }} {# 3.76 Mb #}
{{ "5838388588776"|filesizeformat }} {# 5.31 Tb #}
{{ "1012"|filesizeformat }} {# 1012 bytes #} {# < 1024 #}
This will divide by 1024, not 1000.
Bugs and Differences to Django
If you find any, pleas report them
first
Returns the first element of a list.
var=>[1,2,3,4];
{{ var|first }} {# 1 #}
{{ "abc"|make_list|first }} {# a #}
Bugs and Differences to Django
Also returns the first value in a hash.
fix_ampersands
Replace `&' with `&'. See `escape' and `force_escape' for a better
solution.
Doesn't mark the value safe.
var=>"Tom & Jerry";
{{ var|fix_ampersands }} {# Tom & Jerry #}
{{ var|fix_ampersands|safe }} {# Tom & Jerry #}
Bugs and Differences to Django
This is somewhat deprecated in Django and replaced by the autoescaping
routines. Don't use this anymore.
floatformat :DIGITS
Formats a (float) value with variables with a number DIGITS after the
dot. If DIGITS is negative, it will cut off trailing zeros (and the
dot).
DIGITS defaults to -1
{{ "1.001"|floatformat }} {# 1 #}
{{ "1.001"|floatformat:"2" }} {# 1.00 #}
Bugs and Differences to Django
If you find any, please put them in the tracker or drop me a mail.
force_escape
Escapes the string at this point in the filter stack (not at the end
like `escape')
` < ', `>', `'', `"' and `&' are converted to `<', `>', `'',
`"' and `&' respectively.
See also `escape'
{{ "<>"|force_escape|escape }} {# <> #}
{{ "<>"|force_escape|safe }} {# <> #}
Bugs and Differences to Django
If you find any, please report them.
get_digit :NTH
Extracts the NTH digit (from the right) of an integer value.
Just returns the value if it was not an integer.
{{ "4893"|get_digit:"3" }} {# 8 #}
{{ "4893"|get_digit:"2" }} {# 9 #}
Bugs and Differences to Django
If you find any, please report them.
iriencode
Encodes Unicode characters according to rfc3987, all characters above
0x7f are encoded.
You won't need this filter if the output of the script is already
Unicode.
This does not replace urlencode, but should be used in conjunction with
it.
The result from iriencode of an iriencoded string will not change it
anymore.
{{ "http://www.google.com/?q=\u0334%20"|iriencode }} {# http://www.google.de/?q=%CC%B4%20 #} {# %20 stayed #}
http://www.google.com/?q={{ var|urlencode|iriencode }}&hl=en {# The best way if var contains urlunsafe chars and unicode chars #}
Bugs and Differences to Django
This won't work on EBCDIC Systems for now, sadly.
If you find anything else, please report them.
join :STRING
Joins a list-value by a STRING.
var=>["Foo","Bar","!"];
{{ var|join:" : " }} {# Foo : Bar : ! #}
{{ "4893"|make_list|join:"," }} {# 4,8,9,3 #}
Bugs and Differences to Django
If you find any, please report them.
last
Returns the last element of a list. (See also `first')
var=>[1,2,3,4];
{{ var|first }} {# 4 #}
{{ "abc"|make_list|first }} {# c #}
Bugs and Differences to Django
Also returns the last value in a hash.
length
Returns the length of arrays, lists or strings.
The returned value is always marked safe (not that it matters for
output)
var=>[10,2,73,64];
{{ var|length }} {# 4 #}
{{ "abc"|length }} {# 3 #}
Bugs and Differences to Django
Tries to call count() on objects to get the length.
`undef' (`none' in python) will be counted as "".
length_is :LENGTH
Returns 1 if the length of arrays, lists or strings is equal to LENGTH,
"" otherwise.
The returned value is always marked safe (not that it matters for
output)
var=>[10,2,73,64];
{% if var|length_is:"4" %}1{% else %}0{% endif %} {# 1 #}
{% if "abc"|length_is:"2" %}1{% else %}0{% endif %} {# 0 #}
Bugs and Differences to Django
Tries to call count() on objects to get the length.
Unknown datastructers (GLOBS, FILEHANDLES, SCALARREFS ... ) will never
return true.
`undef' (`none' in python) will be counted as "".
linebreaks
Converts newlines in the value to paragraphs (<p>) and breaks <br>. The
output will always be a paragraph.
Two linebreaks/newlines (\n\n) start a new paragraph, a single one gets
converted into a <br /> tag.
This filter will apply escaping and return a safe string. Otherwise the
<p> and <br /> tags are going to be messed up
{{ "Hello\nWorld"|linebreaks }} {# <p>Hello<br />World</p> #}
{{ "Hello\nWorld\n\n<b>Foo</b>"|escape|linebreaks|safe }} {# <p>Hello<br />World</p><p><b>Foo</b></p>#}
Bugs and Differences to Django
This might mess up your HTML if the variable is marked safe, this will
appear if you want the user to include HTML or something like BBCode.
You will have to use `linebreaksbr' (See below) for that.
{{ "<b>...\n\n..</b>"|safe|linebreaks }} {# <p><b>...</p><p>..</b></p> #} {# Invalid: You can see how the <b> tag is split up #}
<p>{{ "<b>...\n\n..</b>"|safe|linebreaksbr }}</p> {# <p><b>...<br /><br />..</b></p> #} {# Valid! #}
Many BBCode interpreters don't replace linebreaks by themselves. (In
most forums for example you can as a user switch on "Post is HTML" "Post
is BBCode" "Convert linebreaks")
linebreaksbr
Converts newlines into breaks <br>.
This filter will apply escaping and return a safe string. Otherwise the
<br /> tags are going to be messed up
{{ "Hello\nWorld"|linebreaksbr }} {# Hello<br />World #}
{{ "Hello\nWorld\n\n<b>Foo</b>"|escape|linebreaksbr|safe }} {# Hello<br />World<br /><br /><b>Foo</b>#}
Bugs and Differences to Django
If you find any, please report them
linenumbers
Writes a linenumber before each line.
{{ "Hello\nWorld"|linenumbers }}
{# 1: Hello
2: World #}
{{ "Hello\nWorld\n\n<b>Foo</b>"|escape|linenumbers|safe }}
{# 1: Hello
2: World
3:
4: <b>Foo</b> #}
Bugs and Differences to Django
If you find any, please report them
ljust :FIELDWIDTH
Leftjustifies a text in a field of FIELDWIDTH spaces.
This is not usefull for HTML (unless in <pre> like tags), but for
email's from forms or other text files.
{{ "Hello"|ljust:"20" }} {# "Hello " #}
The string is not truncated if it's larger than FIELDWIDTH
Bugs and Differences to Django
Also supports a padding parameter, if you want something other than
spaces:
{{ "Hello":ljust:"20";"-" }} {# "Hello---------------" #}
lower
Converts the value into lowercase.
{{ "Hello, World"|lower }} {# hello, world #}
Bugs and Differences to Django
If you find any, please report them
make_list
Splits a value into a list of characters
{% for x in "abc"|make_list %}{{ x }}{% if not forloop.last %},{% endif %}{% endfor %}{# a,b,c #}
{{ "def"|make_list|join:"," }} {% d,e,f %}
Bugs and Differences to Django
If given a parameter it splits at the parameter:
{{ "b,c,d"|make_list:","|join:" " }} {# b c d #}
phone2numeric
Converts a value into a phonenumber.
All this does is replace A-Y (without Q) with 2-9.
{{ "800-FOOBAR"|phone2numeric }}{# 800-366227 #}
{{ "Hello, World"|phone2numeric }} {% 43556, 96753 %}
Bugs and Differences to Django
This has no locale support for now, locales will have to redefine this
one.
pluralize :STRING
Prints a different STRING if the value is not "1". This is very useful
if you want to pluralize a value.
When STRING contains a comma ("y,ies") it will either take the first
value on 1 and the other one in any other case.
The STRING defaults to "s".
1 template{{ "1"|pluralize }}, 3 template{{ "3"|pluralize }} {# 1 template, 3 templates #}
1 walrus{{ "1"|pluralize:"es" }}, 4 walrus{{ "4"|pluralize:"es" }} {# 1 walrus, 4 walruses #}
1 berr{{ "1"|pluralize:"y,ies" }}, 6 berr{{ "6"|pluralize:"y,ies" }} {# 1 berry, 6 berries #}
Bugs and Differences to Django
Since Dotiac::DTL also supports multiple arguments to filters, you can
also write this:
1 cherr{{ "1"|pluralize:"y";"ies" }}, 6 cherr{{ "6"|pluralize:"y";"ies" }} {# 1 cherry, 6 cherries #}
This is useful if one of your STRINGs contains a comma.
1 {{ "1"|pluralize:"";", and that's all" }}, 2 {{ "2"|pluralize:"";", and that's all" }} {# 1, 2, and that's all #}
pprint
For Debug
Bugs and Differences to Django
Uses Data::Dumper instead of pprint
random
Returns a random element of a list. (See also `first' and `last')
var=>[1,2,3,4];
{{ var|first }} {# 3 #} {# or 1 or 2 or 4 #}
{{ "abc"|make_list|first }} {# c #} {# or a or b #}
Bugs and Differences to Django
Also returns a random value of a hash.
removetags :TAGS
Removes HTML (XML) TAGS from the value. TAGS is a space seperated list
of tags to be removed
{{ "<p><b>Hello</b>World</p>"|removetags:"b" }} {# <p>HelloWorld</p> #}
{{ "<p><b>H<u>el</u>lo</b><span class="w">World</span></p>"|removetags:"b span" }} {# <p>H<u>el</u>loWorld</p> #}
See `striptags' if you want to strip all tags from the value.
Bugs and Differences to Django
If you find any, please report them.
rjust :FIELDWIDTH
Rightjustifies a text in a field of FIELDWIDTH spaces.
This is not usefull for HTML (unless in <pre> like tags), but for
email's from forms or other text files.
{{ "Hello"|rjust:"20" }} {# " Hello" #}
The string is not truncated if it's larger than FIELDWIDTH
Bugs and Differences to Django
Also supports a padding parameter, if you want something other than
spaces:
{{ "Hello":ljust:"20";"-" }} {# "---------------Hello" #}
safe
Marks a string as safe, i.e. in no need of escaping for output.
Also see `escape'.
var="<>";
{{ var|safe }} {# <> #}
{{ var|escape|cut:"&"|safe }} {# <> #} {# Escaping is done only once after all filter are applied #}
Bugs and Differences to Django
If you find any, please report them.
slice :POSITION
Extracts a sublist out of a list from a POSITION. POSITION is a string
of two number seperated by a ":"
See also
http://diveintopython.org/native_data_types/lists.html#odbchelper.list.s
lice.
var=[1,2,3,4];
{{ var|slice:":2" }} {# [1, 2] #}
{{ var|slice:"1:" }} {# [2, 3, 4] #}
{{ var|slice:"1:2" }} {# [2] #}
{{ var|slice:"-2:-1" }} {# [3] #}
Bugs and Differences to Django
Also allows you to get a single item:
{{ var|slice:"3" }} {# 4 #} Same as: {{ var.3 }}
Also works on hashes. Then it slices the value list orderd by their
keys.
slugify
Converts the value to lowercase, removes all non word characters,
removes trailing and leading whitespaces and replaces all other spaces
with a "-".
The resulting value is marked safe.
This is useful if you want to generate a save ID for something like a
name an user entered, while keeping the original meaning.
{{ "Hello World"|slugify }} {# hello-world #}
{{ "<b>Foo</b>"|slugify }} {# bfoob #}
Bugs and Differences to Django
If you find any, please report them.
stringformat :FORMAT
FORMATs a value according to python's format rules. (str.format:
http://docs.python.org/library/stdtypes.html#str.format)
The leading % is dropped. ("%s" = "s"),
{{ "Hello World"|stringformat:"s" }} {# Hello World #}
{{ "3"|stringformat:"#+05b" }} {# 0b011 #}
{{ "3"|stringformat:"#+02d" }} {# +03 #}
Bugs and Differences to Django
This uses perl's sprintf, which is about the same as python's format.
See the sprintf entry in the perlfunc manpage
"r" is emulated
striptags
Removes all HTML (XML) tags from the value.
{{ "<p><b>Hello</b>World</p>"|striptags }} {# HelloWorld #}
{{ "<p><b>H<u>el</u>lo</b><span class="w">World</span></p>"|striptags }} {# HelloWorld #}
See `removetags' if you want to remove only some tags from the value.
Bugs and Differences to Django
If you find any, please report them.
time :FORMAT
Formats a time, according to a FORMAT.
This only formats for time. See `date' if you want to format date and
time.
{{ "20002312"|time:"H:i" }} {# 14:11 #}
{{ post.time|time:"P" }} {# noon #}
The retured value will be safe if the FORMAT string is safe.
Format options
You can combine as many of these as you like or need:
{{ var|time:"G:i A" }}
"\" Returns the next character, regardless if it is a format character
or not.
{{ var|time: "\H\e\l\l\o \W\o\r\l\d" %} {# =Hello World #}
This also means "\n" will in this case render an "n" and NOT a
newline. Same for "\t","\f","\b","\r".
"a" Returns whether it is AM or PM in Associated Press style: "a.m." or
"p.m".
{{ var|time: "a" }} {# a.m. on in the morning#}
This might change if a locale module is loaded.
"A" Returns AM or PM.
{{ var|time: "A" }} {# AM #}
This might change if a locale module is loaded.
"f" Returns the time with hours and minutes, but minutes are left out if
they are 0.
{{ var|time: "f" }} o'clock {# 11:30 o'clock #} {# 3 o'clock #}
"g" Returns the hour in 12-hour format without leading zeros.
{{ var|time: "g" }} {# 1 #} to {# 12 #}
"G" Returns the hour in 24-hour format without leading zeros.
{{ var|time: "G" }} {# 0 #} to {# 24 #}
"h" Returns the hour in 12-hour format with a leading zero.
{{ var|time: "h" }} {# 01 #} to {# 12 #}
"H" Returns the hour in 24-hour format with a leading zero.
{{ var|time: "H" }} {# 00 #} to {# 24 #}
"i" Returns the minutes with a leading zero.
{{ var|time: "i" }} {# 00 #} to {# 60 #}
"O" Returns the difference to Greenwich time in hours.
{{ var|time: "O" }} {# +0100 #}
"P" Returns either the time in 12 hours and minutes if not zero with
a.m. or p.m., midnight or noon.
{{ var|time: "P" }} {# 1 p.m. #} {# 11:56 a.m. #} {# midnight #} {# noon #}
"s" Returns the seconds with a leading zero.
{{ var|time: "s" }} {# 00 #} to {# 59 #}
"Z" Returns the difference of the current timezone to GMT in seconds.
{{ var|time: "Z" }} {# -43200 #} to {# 43200 #}
Bugs and Differences to Django
Since Perl has no default DateTime Object, this expects a normal unix
timestamp ( result of the time() call in perl).
It also excepts the result of localtime as an array reference, this is
useful for timestamps > 2038 on 32-Bit machines.
var=>[36,31,21,2,0,109,5,1,0];
{{ var|time:"H:i" }} {# 21:31 #}
timesince :REFERNCETIME
Formats a time value and displays the time since REFERENCE TIME has
passed.
REFERENCETIME is `now' if it is omitted
If you have a past event and want to display the time since then you can
use this filter.
For any time in the future it will return 0 Minutes
{{ post.date|timesince }} {# 3 years #}
{{ post.date|timesince:edit.date }} {# 3 minutes #} {# after the post #}
`timesince' and `timeuntil' only differ in the order of the arguments:
{{ date1|timeuntil:date2 }} == {{ date2|timesince:date1 }}
The generated value is always marked as safe.
Bugs and Differences to Django
Like `time' and `date' it only accepts unix timestamps.
If given any additional parameter it will print out the full time, while
without it will only print useful information
{{ post.date|timesice:edit.date;"" }} {# 2 days 3 Minutes #}
{{ post.date|timesice:"now";"" }} {# 3 years 2 days 2 seconds #} {# compare to current time #}
If you have just a elapsed time in seconds you can use this:
{{ "0"|timesince:"60" }} {# 1 Minute #}
timeuntil :REFERNCETIME
Formats a time value and displays the time util REFERENCE TIME.
REFERENCETIME is `now' if it is omitted.
If you have a funture event and want to display the time util then you
can use this filter
For any time in the past it will return 0 Minutes
{{ marriage.date|timeuntil }} {# 3 years #}
{{ marriage.date|timeuntil:engagement.date }} {# 3 month #} {# after the engagement #}
`timesince' and `timeuntil' only differ in the order of the arguments:
{{ date1|timesince:date2 }} == {{ date2|timeuntil:date1 }}
The generated value is always marked as safe.
Bugs and Differences to Django
Like `time' and `date' it only accepts unix timestamps.
If given any additional parameter it will print out the full time, while
without it will only print useful information
{{ post.date|timeuntil:edit.date;"" }} {# 3 month 3 Minutes #}
{{ marriage.date|timeuntil:"now";"" }} {# 3 years 2 days 2 seconds #} {# compare to current time #}
If you have just a elapsed time in seconds you can use this:
{{ "60"|timeuntil:"0" }} {# 1 Minute #}
title
Converts the value into titlecase.
{{ "500 kilos of heroin found"|title }} {# 500 Kilos Of Heroin Found #}
Bugs and Differences to Django
If you find any, please report them
truncatewords :NUMBEROFWORDS
Cuts off the value after a specific NUMBER OF WORDS. Replaces the
removed parts with "..."
{{ "500 kilos of heroin found"|truncatewords:"3" }} {# 500 kilos of ... #}
{{ "Today is monday"|truncatewords:"3" }} {# Today is monday #}
Bugs and Differences to Django
If you find any, please report them
truncatewords_html :NUMBEROFWORDS
Cuts off the value after a specific NUMBER OF WORDS. Replaces the
removed parts with "..."
Same as `truncatewords', but also closes every HTML/XML Tag that's left
open after the cutoff.
{{ "<b>500 kilos <u>of</u> heroin found</b>"|truncatewords:"3" }} {# <b>500 kilos <u>of</u> ...</b> #}
{{ "Today <u>is</u> monday"|truncatewords:"3" }} {# Today <u>is</u> monday #}
This one is much slower than truncatewords, so use this only when you
have HTML tags in your value.
Returns a safe string and escapes an unsafe value.
Bugs and Differences to Django
If you have a six word string and a tag after the sixth word and you
truncate to six words, it will still insert a "...".
unordered_list
Converts a list-value of list into a HTML-unordered list without the
surrounding <ul> Tag.
var=>[
"Continents",
[
"North America",
["USA","Kanada"],
"South America",
["Mexico"],
"Europe"
"Australia"
"Asia"
]
]
{{ var|unordered_list:"3" }}
{#
<li>Continents
<ul>
<li>North America
<ul>
<li>USA</li>
<li>Kanada</li>
</ul>
</li>
<li>South America
<ul>
<li>Mexico</li>
</ul>
</li>
<li>Europe</li>
<li>Australia</li>
<li>Asia</li>
</ul>
</li>
#}
Also supports the old format.
The returned value is always escaped (if unsafe) and marked safe.
Bugs and Differences to Django
The old verbose format is supported, but I don't trust the
implementation. (It works, I don't know why)
urlencode
Converts all characters except wordcharacters, minus, "~" and "/" to be
used in an url
http://www.google.com/?q={{ "Hello World"|urlencode }} {# http://www.google.com/?q=Hello%20World #}
Bugs and Differences to Django
If given an argument it allows for more characters to not be encoded.
{{ "http://www.google.com/?q=Hello World"|urlencode }} {# http%3A//www.google.com/%3Fq%3DHello%20World #}
{{ "http://www.google.com/?q=Hello World"|urlencode:":?=&" }} {# http://www.google.com/?q=Hello%20World #}
upper
Converts the value into uppercase. (Also see `lower')
{{ "Hello, World"|upper }} {# HELLO, WORLD #}
Bugs and Differences to Django
If you find any, please report them
urlize
Converts all urls in the value.
{{ "Go to www.dotiac.com and be happy"|urlize }} {# Go to <a href="www.dotiac.com" rel="nofollow">www.dotiac.com</a> and be happy #}
The value is escaped if needed and marked safe.
Bugs and Differences to Django
This uses a regular expression, so it might find different urls than
Django.
This filter is not aware of <a href="..."></a> tags so it will convert
the url in that. This should be fixed in the future.
urlizetrunc :LENGTH
Converts all urls in the value and truncates the output to LENGHT.
LENGTH defaults to 15.
{{ "Go to www.dotiac.com and be happy"|urlizetrunc:8 }} {# Go to <a href="www.dotiac.com" rel="nofollow">www.doti...</a> and be happy #}
The value is escaped if needed and marked safe.
Bugs and Differences to Django
This uses a regular expression, so it might find different urls than
Django.
This filter is not aware of <a href="..."></a> tags so it will convert
the url in that. This should be fixed in the future.
wordcount
Counts the number of words in the value
{{ "Hello World"|wordcount }} {# 2 #}
The returned value is always safe.
Bugs and Differences to Django
If you find any, please report them.
wordwrap :AMOUNT_OF_CHARACTERS
Wraps the valuetext after a given AMOUNT OF CHARACTERS, but doesn't rip
apart words.
AMOUNT_OF_CHARACTERS defaults to 80.
{{ "This is some text without meaning"|wordwrap:7 }}
{# This is
some
text
without
meaning #}
Bugs and Differences to Django
If you find any, please report them.
yesno :STRINGS
Returns a different STRING depending on the value. STRINGS is a comma
seperated list of 2 or 3 strings.
The first string is the content returned if the value is true, the
second is the content if it's false and the third is the content if the
value is `null' (`undef' in perl).
If the thrid value is not given it defaults to the second one.
true=>1,
false=>0,
null=>undef
{{ true|yesno:"do it, don't do it" }} {# do it #}
{{ false|yesno:"do it, don't do it" }} {# don't do it #}
{{ null|yesno:"do it, don't do it" }} {# don't do it #}
{{ true|yesno:"yes, no, don't care" }} {# yes #}
{{ false|yesno:"yes, no, don't care" }} {# no #}
{{ null|yesno:"yes, no, don't care" }} {# don't care #}
Bugs and Differences to Django
You can also give it three seperate arguments, this is quite useful for
variables.
{{ var|yesno:ontrue;onfalse;onnull }}
SEE ALSO
http://www.djangoproject.com, the Dotiac::DTL manpage
LEGAL
Dotiac::DTL was built according to
http://docs.djangoproject.com/en/dev/ref/templates/builtins/.
AUTHOR
Marc-Sebastian Lucksch
perl@marc-s.de
API-tillägg för Orion-filter
append
Tar ett enda argument och lägger till dess värde i de filtrerade indata. Argumentet kan vara ett varname eller en sträng inom citattecken. Det här filtret är smart om / tecken som förenas på append.
cuts
Liknar cut, men argumentet tas som en understräng för att elidera, i stället för en lista med tecken.
lede
Extraherar texten mellan {# lede #} block i den filtrerade indatasträngen.
ssi
Utvärderar alla Django ssi taggar i den filtrerade indatasträngen.
starts_with
Tester för prefixmatchning.
dirname
Returnerar det traditionella UNIX dirname för sökvägen i den filtrerade indatasträngen.
parse_filename
Gränssnitt för SunStarSys::Util::parse_filename. Den viktigaste skillnaden är att de två första returvärdena för den subrutinen byts ut och banans förlängningar bryts ut (med . med prefix) i enskilda argument, vilket gör att filtret kan ta en argumentsträng som representerar en lista med index i den resulterande uppställningen. Ett argument som slutar med .. kommer att ansluta till alla tolkade tillägg till slutet av den resulterande strängen.
basename
Returnerar det traditionella UNIX basename för sökvägen i den filtrerade indatasträngen. Att argumentera för 0 till det här filtret kommer det att ta bort alla filtillägg från den resulterande strängen.
tex2md
Transformeringar källor till nedsättning+ källor. Experimentell.
md2tex
Produktionskvalitetsomvandling av tex2md.
vcs_date
Tar en lang argument för att tillhandahålla en språkspecifik representation av dag, månad och år för den senaste ändringen som presenteras av $Date Subversion-nyckelord i den filtrerade indatasträngen (som vanligtvis är hela content den nuvarande resursen).
vcs_time
Representerar den numeriska tim-, minut-, sekund- och tidszonsförskjutningen för den senaste ändringen som presenteras av $Date Subversion-nyckelord i den filtrerade indatasträngen.
vcs_author
Visar en safe HTML återgivning av den användare som senast uppdaterade innehållet, som registrerats med nyckelordet Subversion $Author nyckelordet i den filtrerade indatasträngen. Tar ett valfritt alternativ lang argument för en språkspecifik representation.
vcs_revision
Visar det numeriska revisionsnumret för den senaste ändringen av innehållet, som registrerats av $Revision nyckelordet i den filtrerade indatasträngen.
strip_prefix
Tar bort prefixet (sökväg), som skickas som ett argument till det här filtret, från den filtrerade indatasträngen (sökväg). Prefixet är som standard det reguljära uttrycket \S+/content/ annars.
selectattr
Söker efter det första matchande html-taggattributet, med attributnamnet som ett argument till filtret.
shuffle
Blanda matrisen.
split
Delar indatasträngen i en uppställning baserat på det mönster som skickas som argument.
img
Hämta den första HTML5/Markdown-bilden från det filtrerade innehållet.
pdl_*
Fullständig PDL API. Om du överför det här filtret en arrayref som argument avrefereras arrayen så att dess element kan överföras direkt till pdl_ metod med prefix som detta filter anropar.
grep
Samma som det välkända verktyget UNIX/Perl; du skickar det ett reguljärt uttryck som argument och det filtrerar ut det icke-PCRE-matcha källor.
fenced
Hämtar en matris med GFM inhägnad kod blockerar ur källan; du skickar det namnet / typen av kodblock du önskar.
