|
NAMETemplate::View - customised view of a template processing context SYNOPSIS # define a view
[% VIEW view
# some standard args
prefix => 'my_',
suffix => '.tt2',
notfound => 'no_such_file'
...
# any other data
title => 'My View title'
other_item => 'Joe Random Data'
...
%]
# add new data definitions, via 'my' self reference
[% my.author = "$abw.name <$abw.email>" %]
[% my.copy = "© Copyright 2000 $my.author" %]
# define a local block
[% BLOCK header %]
This is the header block, title: [% title or my.title %]
[% END %]
[% END %]
# access data items for view
[% view.title %]
[% view.other_item %]
# access blocks directly ('include_naked' option, set by default)
[% view.header %]
[% view.header(title => 'New Title') %]
# non-local templates have prefix/suffix attached
[% view.footer %] # => [% INCLUDE my_footer.tt2 %]
# more verbose form of block access
[% view.include( 'header', title => 'The Header Title' ) %]
[% view.include_header( title => 'The Header Title' ) %]
# very short form of above ('include_naked' option, set by default)
[% view.header( title => 'The Header Title' ) %]
# non-local templates have prefix/suffix attached
[% view.footer %] # => [% INCLUDE my_footer.tt2 %]
# fallback on the 'notfound' template ('my_no_such_file.tt2')
# if template not found
[% view.include('missing') %]
[% view.include_missing %]
[% view.missing %]
# print() includes a template relevant to argument type
[% view.print("some text") %] # type=TEXT, template='text'
[% BLOCK my_text.tt2 %] # 'text' with prefix/suffix
Text: [% item %]
[% END %]
# now print() a hash ref, mapped to 'hash' template
[% view.print(some_hash_ref) %] # type=HASH, template='hash'
[% BLOCK my_hash.tt2 %] # 'hash' with prefix/suffix
hash keys: [% item.keys.sort.join(', ')
[% END %]
# now print() a list ref, mapped to 'list' template
[% view.print(my_list_ref) %] # type=ARRAY, template='list'
[% BLOCK my_list.tt2 %] # 'list' with prefix/suffix
list: [% item.join(', ') %]
[% END %]
# print() maps 'My::Object' to 'My_Object'
[% view.print(myobj) %]
[% BLOCK my_My_Object.tt2 %]
[% item.this %], [% item.that %]
[% END %]
# update mapping table
[% view.map.ARRAY = 'my_list_template' %]
[% view.map.TEXT = 'my_text_block' %]
# change prefix, suffix, item name, etc.
[% view.prefix = 'your_' %]
[% view.default = 'anyobj' %]
...
DESCRIPTIONTODO METHODSnew($context, \%config)Creates a new Template::View presenting a custom view of the specified $context object. A reference to a hash array of configuration options may be passed as the second argument.
print( $obj1, $obj2, ... \%config)TODO view( $template, \%vars, \%config );TODO AUTHORAndy Wardley <abw@wardley.org> <http://wardley.org/> COPYRIGHTCopyright (C) 2000-2022 Andy Wardley. All Rights Reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSOTemplate::Plugin
|