NAME
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" : "FooÒô+"
} #}
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
Dotiac::DTL, Dotiac::DTL::Addon, http://www.dotiac.com, http://www.djangoproject.com
AUTHOR
Marc-Sebastian Lucksch
perl@marc-s.de
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 148:
Non-ASCII character seen before =encoding in '{"List":[1,2,3],"Value":"FooÒô+"}">'. Assuming CP1252