GX::View::Template

Module Version: 0.2000_01

NAME

GX::View::Template - Base class for template-based view components

SYNOPSIS

None.

DESCRIPTION

This module provides the GX::View::Template class which extends the GX::View class.

METHODS

Constructor

new

Returns the view component instance.

$view = $view_class->new;
Returns:
Exceptions:

Public Methods

All public methods can be called both as instance and class methods.

default_content_type

Returns the default content type.

$content_type = $view->default_content_type;
Returns:
  • $content_type ( string | undef )

    Returns the default content type, for example "text/html" or "application/xhtml+xml", or undef if the default content type is not defined.

default_encoding

Returns the name of the default output encoding.

$encoding = $view->default_encoding;
Returns:
  • $encoding ( string | undef )

    An encoding name, for example "utf-8" or "iso-8859-1", or undef if the default output encoding is not defined.

file_extensions

Returns a list with the associated template file extensions.

@file_extensions = $view->file_extensions;
Returns:
  • @file_extensions ( strings )

    A list of template file extensions, for example "htc" or "tt".

options

Returns the setup options for the template engine as a list of key / value pairs.

%options = $view->options;
Returns:
  • %options ( named list )

preloaded_templates

Returns a list with the file names of the preloaded templates.

@templates = $view->preloaded_templates;
Returns:

render

If called in void context, render() renders the specified template and adds the result to the body of the response object that is associated with the given context object. Additionally, it sets the "Content-Type" header of the response to an appropriate value, unless that header has already been set.

$view->render( %arguments );
Arguments:
  • context ( GX::Context object ) [ required ]

    A context object. This argument is required in void context.

  • encoding ( string | undef )

    The name of the desired output encoding, for example "utf-8" or "iso-8859-1". See Encode for a list of supported encodings. If omitted, the default encoding will be applied. If undef is passed, the output will not be encoded.

  • options ( HASH reference )

    A reference to a hash with additional render options for the template engine.

  • parameters ( HASH reference )

    A reference to a hash containing the template parameters.

  • template ( string ) [ required ]

    The template to render. The given argument must be a UNIX-style path relative to the templates directory, for example "blog/posts.html.tt".

Exceptions:

If called in non-void context, render() returns the processed template.

$output = $view->render( %arguments ); 
Arguments:
  • context ( GX::Context object )

    A context object. This argument is optional in non-void context.

  • encoding ( string | undef )

    See above.

  • options ( HASH reference )

    See above.

  • parameters ( HASH reference )

    See above.

  • template ( string ) [ required ]

    See above.

Returns:
  • $output ( string | byte string )
Exceptions:

setup

Sets up the view.

$view->setup( %options );
Options:
  • default_content_type ( string )

    The default content type, for example "text/html" or "application/xhtml+xml". Used when the content type is not predetermined by the name of the template file, i.e. for all template files not following the recommended name.format.extension naming scheme.

  • default_encoding ( string )

    The name of the default output encoding, for example "utf-8" or "iso-8859-1". See Encode for a list of supported encodings. Defaults to the default encoding of the application.

  • file_extensions ( ARRAY reference )

    A reference to an array containing the file extensions that should be associated with the view.

  • options ( HASH reference )

    A reference to a hash with additional setup options for the template engine.

  • preload ( bool )

    A boolean flag indicating whether or not to preload all template files located in the templates directory. Defaults to true.

  • template_encoding ( string )

    The name of the encoding of the template files, for example "utf-8" or "iso-8859-1". See Encode for a list of supported encodings. Defaults to the default encoding of the application.

  • templates_directory ( string )

    The path to the directory that contains the template files. Defaults to the application's ./templates directory. A relative path, if given, is assumed to be relative to the application's base directory.

Exceptions:

template_encoding

Returns the name of the encoding of the template files.

$encoding = $view->template_encoding;
Returns:
  • $encoding ( string | undef )

    An encoding name, for example "utf-8" or "iso-8859-1", or undef if the template encoding is not defined.

templates

Returns a list with the file names of the available templates.

@templates = $view->templates;
Returns:

templates_directory

Returns the path to the directory that contains the template files.

$path = $view->templates_directory;
Returns:
  • $path ( string )

SUBCLASSES

The following classes inherit directly from GX::View::Template:

AUTHOR

Jörg A. Uzarek <uzarek@runlevelnull.de>

COPYRIGHT AND LICENSE

Copyright © 2009-2011 Jörg A. Uzarek.

This module is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License Version 3 as published by the Free Software Foundation.