NAME

Top Close Open

Template::TT3::Service::Layout - service module for adding a page layout

SYNOPSIS

Top Close Open
use Template3;

my $tt3 = Template3->new(
    layout => 'site/layout.tt3',
);

DESCRIPTION

Top Close Open

This module is a subclass of Template::TT3::Service for adding a page layout to a template. A page layout is a template containing a reference to a content variable and/or any other slot definitions that can be filled by blocks in the input templates . The layout template is processed with the content variable set to a closure which renders the output from the rest of the service pipeline. The context is set to be visiting the main template so that slot definitions in the layout template can be filled from the main page template.

TODO: rewrite the above in plain English

CONFIGURATION OPTIONS

Top Close Open

template

Top Close Open

Used to specify the default template that should be used for a layout. It can be specified as anything that the Template::TT3::Templates template() method will accept, e.g. a template name, text references, subroutine reference, etc.

template is the default option for the service. Thus the following:

my $layout = Template::TT3::Services->service(
    layout => 'site/layout.tt3',
);

is syntactic sugar for:

my $layout = Template::TT3::Services->service(
    layout => {
        template => 'site/layout.tt3',
    },
);

name

Top Close Open

This can be used to change the name of the service component. The default name is layout. If a layout is specified in the environment passed to the pipeline service function then it will be used in preference to the default template .

$pipeline->(
    context => $context,
    input   => 'example.tt3',
    layout  => 'my/layout.tt3',     # over-ride default layout template
);

METHODS

Top Close Open

This module implements the following methods in addition to those inherited from the Template::TT3::Service , Template::TT3::Base and Badger::Base base class modules.

serve(\%env, $pipeline)

Top Close Open

This is the main service method. It is called automatically when the service is bound in a pipeline that is executed. A copy of the environment is passed as the first argument (a reference to a hash array). A reference to a subroutine representing the rest of the pipeline is passed as the second argument.

The method looks in the environment for an item named layout, or whatever alternate name the service has been given (e.g. site_layout, section_layout, etc). If the item isn't specified then it instead uses the default layout template defined when the service is created. If that is undefined or set to a false value (e.g. 0 or the empty string '') then no layout is added.

Rendering a layout template is a little complicated. First we have to push the main page template onto the context's visit stack. This is so that slot definitions in the layout template can be filled by block definition in the main page template. Then we define a closure which renders the pipeline content and bind this to the content variable. Then we render the layout template.

TODO: tidy up the above.

AUTHOR

Top Close Open

Andy Wardley http://wardley.org/

COPYRIGHT

Top Close Open

Copyright (C) 1996-2009 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 ALSO.

Top Close Open

This module inherits methods from the Template::TT3::Service , Template::TT3::Base and Badger::Base base classes.

Services are loaded and instantiated by the Template::TT3::Services factory module. This is accessible via the Template::TT3::Hub module. The Template::TT3::Engine::TT3 module uses the services module to construct a template processing pipeline.

Other similar services include Template::TT3::Service::Header , Template::TT3::Service::Footer , Template::TT3::Service::Layout , Template::TT3::Service::Before and Template::TT3::Service::After .


http://tt3.template-toolkit.org/docs/Template/TT3/Service/Layout.pm last modified 2009-12-18 07:20:30