Vitali Peil
and 5 contributors


Catmandu::Exporter::Template - a TT2 Template exporter in Catmandu style


    # From the command line
    echo '{"colors":["red","green","blue"]}' | 
        catmandu convert JSON to Template --template `pwd`/

    where like:

    [% FOREACH c IN colors %]
       <color>[% c %]</color>
    [% END %]

    # From perl
    use Catmandu::Exporter::Template;

    my $exporter = Catmandu::Exporter::Template->new(
                fix => 'myfix.txt'
                xml => 1,
                template_before => '<path>/header.xml' ,
                template => '<path>/record.xml' ,
                template_after => '<path>/footer.xml' ,

    $exporter->add_many(sub { });


    $exporter->commit; # trigger the template_after

    printf "exported %d objects\n" , $exporter->count;


This Catmandu::Exporter can be used to export records using Template Toolkit. If you are new to Catmandu see Catmandu::Tutorial.


Catmandu::Exporter::Template derives from Catmandu::Exporter with all of its methods (add, add_many, count, and log). The following methods are supported in addition:


The only required argument is 'template' which points to a file to render for each exported object. Set the 'template_before' and 'template_before' to add output at the start and end of the export. Optionally provide an 'xml' indicator to include a XML header.

  • template: Required. Must contain path to the template.

  • xml: Optional. Value: 0 or 1. Prepends xml header to the template.

  • template_before: Optional. Prepend template.

  • template_after: Optional. Append template.

  • fix: Optional. Apply Catmandu fixes while exporting.

  • start_tag

  • end_tag

  • tag_style

  • interpolate

  • eval_perl


Commit all changes and execute the template_after if given.


Catmandu::Exporter, Template