NAME
MsOffice::Word::Template::Engine::TT2 -- Word::Template engine based on the Template Toolkit
SYNOPSIS
my $template = MsOffice::Word::Template->new(docx => $filename
engine_class => 'TT2',
engine_args => \%args_for_TemplateToolkit,
);
my $new_doc = $template->process(\%data);
See the main synopsis in MsOffice::Word::Template.
DESCRIPTION
Implements a templating engine for MsOffice::Word::Template, based on the Template Toolkit.
AUTHORING NOTES SPECIFIC TO THE TEMPLATE TOOLKIT
This chapter just gives a few hints for authoring Word templates with the Template Toolkit.
The examples below use [[double square brackets]] to indicate segments that should be highlighted in green within the Word template.
Bookmarks
The template processor is instantiated with a predefined wrapper named bookmark
for generating Word bookmarks. Here is an example:
Here is a paragraph with [[WRAPPER bookmark name="my_bookmark"]]bookmarked text[[END]].
The name
argument is automatically truncated to 40 characters, and non-alphanumeric characters are replaced by underscores, in order to comply with the limitations imposed by Word for bookmark names.
Internal hyperlinks
Similarly, there is a predefined wrapper named link_to_bookmark
for generating hyperlinks to bookmarks. Here is an example:
Click [[WRAPPER link_to_bookmark name="my_bookmark" tooltip="tip top"]]here[[END]].
The tooltip
argument is optional.
Word fields
A predefined block field
generates XML markup for Word fields, like for example :
Today is [[PROCESS field code="DATE \\@ \"h:mm am/pm, dddd, MMMM d\""]]
Beware that quotes or backslashes must be escaped so that the Template Toolkit parser does not interpret these characters.
The list of Word field codes is documented at https://support.microsoft.com/en-us/office/list-of-field-codes-in-word-1ad6d91a-55a7-4a8d-b535-cf7888659a51.
When used as a wrapper, the field
block generates a Word field with alternative text content, displayed before the field gets updated. For example :
[[WRAPPER field code="TOC \o \"1-3\" \h \z \u"]]Table of contents - press F9 to update[[END]]
AUTHOR
Laurent Dami, <dami AT cpan DOT org<gt>
COPYRIGHT AND LICENSE
Copyright 2020-2022 by Laurent Dami.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.