| Template-Direct documentation | Contained in the Template-Direct distribution. |
Template::Direct::SubPage - Handle a sub page load
Provide support for loading other templates from the current template.
Create a new instance object.
Modifies a template with the data listed correctly.
Returns the compiled template by loading the file and passing the right scoped data to it.
Load a Template object with the location of the sub page.
Martin Owens - Copyright 2007, AGPL
| Template-Direct documentation | Contained in the Template-Direct distribution. |
package Template::Direct::SubPage; use base Template::Direct::Page; use Template::Direct; use strict; use warnings;
use Carp;
sub new { my ($class, $index, $location, %p) = @_; my $self = $class->SUPER::new(undef, %p); $self->{'startTag'} = $index; $self->{'Location'} = $location; return $self; }
sub compile { my ($self, $data, $template, %p) = @_; return if ref($template) ne 'SCALAR'; my $section = $self->getContents( $data ); # Mark the section as being processed $self->getLocation( $template, $self->{'startTag'} ); # Set the section in the Location $self->setSection($template, $section); }
sub getContents { my ($self, $data) = @_; if(not $self->{'content'}) { $self->{'content'} = $self->loadTemplate(); chomp($self->{'content'}); } return $self->SUPER::compile( $data ); }
sub loadTemplate { my ($self) = @_; my $newdoc = Template::Direct->new( Directory => $self->{'Directory'}, Location => $self->{'Location'}, ); return $newdoc->load( Language => $self->{'Language'} ); }
1;