Template::Direct::SubPage - Handle a sub page load


Template-Direct documentation Contained in the Template-Direct distribution.

Index


Code Index:

NAME

Top

Template::Direct::SubPage - Handle a sub page load

DESCRIPTION

Top

  Provide support for loading other templates from the current template.

METHODS

Top

$class->new( $index, $line )

  Create a new instance object.

$object->compile( )

  Modifies a template with the data listed correctly.

$page->getContents( $data )

  Returns the compiled template by loading the file
  and passing the right scoped data to it.

$page->loadTemplate( )

  Load a Template object with the location of the sub page.

AUTHOR

Top

  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;