Stefan Hornburg (Racke) > Template-Flute > Template::Flute::Filters::JsonVar

Download:
Template-Flute-0.0121.tar.gz

Annotate this POD

View/Report Bugs
Source  

NAME ^

Template::Flute::Filters::JsonVar - JSON to Javascript variable filter

DESCRIPTION ^

Takes a Perl structure or a JSON string and returns Javascript which parses the JSON string with Jquery and assigns it to the variable json.

The following example shows you how to inject the JSON variable into the template:

HTML Template:

    <script type="text/javascript" id="vars"></script>

XML Specification:

    <value name="jsvars" id="vars" filter="json_var"/>

Values for Template::Flute:

    Template::Flute->new(...,
        values => {jsvars =>
          {username => 'shopper@nitesi.biz', city => 'Vienna'},
        },
    );

This results in the following JavaScript:

    <script type="text/javascript" id="vars">
    var json = $.parseJSON('{"city":"Vienna","username":"shopper@nitesi.biz"}');
    </script>

PREREQUISITES ^

JSON module.

METHODS ^

init

The init method allows you to set the following options:

engine

Value is either jquery or eval.

filter

Filters the given Perl structure to a JSON string.

syntax highlighting: