{
    "mode": "perldoc",
    "parameter": "Template::View",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Template%3A%3AView/json",
    "generated": "2026-06-10T16:25:41Z",
    "synopsis": "# define a view\n[% VIEW view\n# some standard args\nprefix        => 'my',\nsuffix        => '.tt2',\nnotfound      => 'nosuchfile'\n...\n# any other data\ntitle         => 'My View title'\notheritem    => 'Joe Random Data'\n...\n%]\n# add new data definitions, via 'my' self reference\n[% my.author = \"$abw.name <$abw.email>\" %]\n[% my.copy   = \"&copy; Copyright 2000 $my.author\" %]\n# define a local block\n[% BLOCK header %]\nThis is the header block, title: [% title or my.title %]\n[% END %]\n[% END %]\n# access data items for view\n[% view.title %]\n[% view.otheritem %]\n# access blocks directly ('includenaked' option, set by default)\n[% view.header %]\n[% view.header(title => 'New Title') %]\n# non-local templates have prefix/suffix attached\n[% view.footer %]           # => [% INCLUDE myfooter.tt2 %]\n# more verbose form of block access\n[% view.include( 'header', title => 'The Header Title' ) %]\n[% view.includeheader( title => 'The Header Title' ) %]\n# very short form of above ('includenaked' option, set by default)\n[% view.header( title => 'The Header Title' ) %]\n# non-local templates have prefix/suffix attached\n[% view.footer %]           # => [% INCLUDE myfooter.tt2 %]\n# fallback on the 'notfound' template ('mynosuchfile.tt2')\n# if template not found\n[% view.include('missing') %]\n[% view.includemissing %]\n[% view.missing %]\n# print() includes a template relevant to argument type\n[% view.print(\"some text\") %]     # type=TEXT, template='text'\n[% BLOCK mytext.tt2 %]           # 'text' with prefix/suffix\nText: [% item %]\n[% END %]\n# now print() a hash ref, mapped to 'hash' template\n[% view.print(somehashref) %]   # type=HASH, template='hash'\n[% BLOCK myhash.tt2 %]           # 'hash' with prefix/suffix\nhash keys: [% item.keys.sort.join(', ')\n[% END %]\n# now print() a list ref, mapped to 'list' template\n[% view.print(mylistref) %]     # type=ARRAY, template='list'\n[% BLOCK mylist.tt2 %]           # 'list' with prefix/suffix\nlist: [% item.join(', ') %]\n[% END %]\n# print() maps 'My::Object' to 'MyObject'\n[% view.print(myobj) %]\n[% BLOCK myMyObject.tt2 %]\n[% item.this %], [% item.that %]\n[% END %]\n# update mapping table\n[% view.map.ARRAY = 'mylisttemplate' %]\n[% view.map.TEXT  = 'mytextblock'    %]\n# change prefix, suffix, item name, etc.\n[% view.prefix = 'your' %]\n[% view.default = 'anyobj' %]\n...",
    "sections": {
        "NAME": {
            "content": "Template::View - customised view of a template processing context\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "# define a view\n[% VIEW view\n# some standard args\nprefix        => 'my',\nsuffix        => '.tt2',\nnotfound      => 'nosuchfile'\n...\n\n# any other data\ntitle         => 'My View title'\notheritem    => 'Joe Random Data'\n...\n%]\n# add new data definitions, via 'my' self reference\n[% my.author = \"$abw.name <$abw.email>\" %]\n[% my.copy   = \"&copy; Copyright 2000 $my.author\" %]\n\n# define a local block\n[% BLOCK header %]\nThis is the header block, title: [% title or my.title %]\n[% END %]\n\n[% END %]\n\n# access data items for view\n[% view.title %]\n[% view.otheritem %]\n\n# access blocks directly ('includenaked' option, set by default)\n[% view.header %]\n[% view.header(title => 'New Title') %]\n\n# non-local templates have prefix/suffix attached\n[% view.footer %]           # => [% INCLUDE myfooter.tt2 %]\n\n# more verbose form of block access\n[% view.include( 'header', title => 'The Header Title' ) %]\n[% view.includeheader( title => 'The Header Title' ) %]\n\n# very short form of above ('includenaked' option, set by default)\n[% view.header( title => 'The Header Title' ) %]\n\n# non-local templates have prefix/suffix attached\n[% view.footer %]           # => [% INCLUDE myfooter.tt2 %]\n\n# fallback on the 'notfound' template ('mynosuchfile.tt2')\n# if template not found\n[% view.include('missing') %]\n[% view.includemissing %]\n[% view.missing %]\n\n# print() includes a template relevant to argument type\n[% view.print(\"some text\") %]     # type=TEXT, template='text'\n\n[% BLOCK mytext.tt2 %]           # 'text' with prefix/suffix\nText: [% item %]\n[% END %]\n\n# now print() a hash ref, mapped to 'hash' template\n[% view.print(somehashref) %]   # type=HASH, template='hash'\n\n[% BLOCK myhash.tt2 %]           # 'hash' with prefix/suffix\nhash keys: [% item.keys.sort.join(', ')\n[% END %]\n\n# now print() a list ref, mapped to 'list' template\n[% view.print(mylistref) %]     # type=ARRAY, template='list'\n\n[% BLOCK mylist.tt2 %]           # 'list' with prefix/suffix\nlist: [% item.join(', ') %]\n[% END %]\n\n# print() maps 'My::Object' to 'MyObject'\n[% view.print(myobj) %]\n\n[% BLOCK myMyObject.tt2 %]\n[% item.this %], [% item.that %]\n[% END %]\n\n# update mapping table\n[% view.map.ARRAY = 'mylisttemplate' %]\n[% view.map.TEXT  = 'mytextblock'    %]\n\n\n# change prefix, suffix, item name, etc.\n[% view.prefix = 'your' %]\n[% view.default = 'anyobj' %]\n...\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "TODO\n",
            "subsections": []
        },
        "METHODS": {
            "content": "new($context, \\%config)\nCreates a new Template::View presenting a custom view of the specified $context object.\n\nA reference to a hash array of configuration options may be passed as the second argument.\n\nprefix\nPrefix added to all template names.\n\n[% USE view(prefix => 'my') %]\n[% view.view('foo', a => 20) %]     # => myfoo\n\nsuffix\nSuffix added to all template names.\n\n[% USE view(suffix => '.tt2') %]\n[% view.view('foo', a => 20) %]     # => foo.tt2\n\nmap Hash array mapping reference types to template names. The print() method uses this to\ndetermine which template to use to present any particular item. The TEXT, HASH and ARRAY\nitems default to 'test', 'hash' and 'list' appropriately.\n\n[% USE view(map => { ARRAY   => 'mylist',\nHASH    => 'yourhash',\nMy::Foo => 'myfoo', } ) %]\n\n[% view.print(sometext) %]         # => text\n[% view.print(alist) %]            # => mylist\n[% view.print(ahash) %]            # => yourhash\n[% view.print(afoo) %]             # => myfoo\n\n[% BLOCK text %]\nText: [% item %]\n[% END %]\n\n[% BLOCK mylist %]\nlist: [% item.join(', ') %]\n[% END %]\n\n[% BLOCK yourhash %]\nhash keys: [% item.keys.sort.join(', ')\n[% END %]\n\n[% BLOCK myfoo %]\nFoo: [% item.this %], [% item.that %]\n[% END %]\n\nmethod\nName of a method which objects passed to print() may provide for presenting themselves to\nthe view. If a specific map entry can't be found for an object reference and it supports the\nmethod (default: 'present') then the method will be called, passing the view as an argument.\nThe object can then make callbacks against the view to present itself.\n\npackage Foo;\n\nsub present {\nmy ($self, $view) = @;\nreturn \"a regular view of a Foo\\n\";\n}\n\nsub debug {\nmy ($self, $view) = @;\nreturn \"a debug view of a Foo\\n\";\n}\n\nIn a template:\n\n[% USE view %]\n[% view.print(myfooobject) %]     # a regular view of a Foo\n\n[% USE view(method => 'debug') %]\n[% view.print(myfooobject) %]     # a debug view of a Foo\n\ndefault\nDefault template to use if no specific map entry is found for an item.\n\n[% USE view(default => 'myobject') %]\n\n[% view.print(objref) %]            # => myobject\n\nIf no map entry or default is provided then the view will attempt to construct a template\nname from the object class, substituting any sequence of non-word characters to single\nunderscores, e.g.\n\n# 'fubar' is an object of class Foo::Bar\n[% view.print(fubar) %]             # => FooBar\n\nAny current prefix and suffix will be added to both the default template name and any name\nconstructed from the object class.\n\nnotfound\nFallback template to use if any other isn't found.\n\nitem\nName of the template variable to which the print() method assigns the current item. Defaults\nto 'item'.\n\n[% USE view %]\n[% BLOCK list %]\n[% item.join(', ') %]\n[% END %]\n[% view.print(alist) %]\n\n[% USE view(item => 'thing') %]\n[% BLOCK list %]\n[% thing.join(', ') %]\n[% END %]\n[% view.print(alist) %]\n\nviewprefix\nPrefix of methods which should be mapped to view() by AUTOLOAD. Defaults to 'view'.\n\n[% USE view %]\n[% view.viewheader() %]                    # => view('header')\n\n[% USE view(viewprefix => 'showmethe' %]\n[% view.showmetheheader() %]             # => view('header')\n\nviewnaked\nFlag to indicate if any attempt should be made to map method names to template names where\nthey don't match the viewprefix. Defaults to 0.\n\n[% USE view(viewnaked => 1) %]\n\n[% view.header() %]                 # => view('header')\n\nprint( $obj1, $obj2, ... \\%config)\nTODO\n\nview( $template, \\%vars, \\%config );\nTODO\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Andy Wardley <abw@wardley.org> <http://wardley.org/>\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Copyright (C) 2000-2007 Andy Wardley. All Rights Reserved.\n\nThis module is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "Template::Plugin\n",
            "subsections": []
        }
    },
    "summary": "Template::View - customised view of a template processing context",
    "flags": [],
    "examples": [],
    "see_also": []
}