|
From: <ix...@us...> - 2001-12-02 09:49:45
|
ixjonez 01/12/02 01:49:43
Added: lib/LiveFrame/Template/Plugin LiveFrame.pm
Log:
add a Template::Toolkit plugin that makes general configuration items
available to templates
Revision Changes Path
1.1 commons/lib/LiveFrame/Template/Plugin/LiveFrame.pm
Index: LiveFrame.pm
===================================================================
# -*- Mode: Perl; indent-tabs-mode: nil; -*-
package LiveFrame::Template::Plugin::LiveFrame;
use strict;
use Template::Plugin ();
@LiveFrame::Template::Plugin::LiveFrame::ISA = ('Template::Plugin');
sub load {
my ($class, $context) = @_;
return $class;
}
sub new {
my ($class, $context, %params) = @_;
my $self = bless
{
context => $context,
};
return $self;
}
sub css_href {
my ($self, $name) = @_;
my $application = $self->variable('application') or
die "template variable [application] not found\n";
return join('/', $application->url($application->config()->css_url()),
$name);
}
sub field {
my ($self, $name) = @_;
my $application = $self->variable('application') or
die "template variable [application] not found\n";
my $form = $self->variable('form');
if ($form) {
my $val = $form->$name();
return $val if defined $val && length($val);
}
return $self->param($name);
}
sub form_action {
my ($self, $name) = @_;
my $application = $self->variable('application') or
die "template variable [application] not found\n";
return join('/', $application->url($application->cgi()->script_name()),
$name);
}
sub img_src {
my ($self, $name) = @_;
my $application = $self->variable('application') or
die "template variable [application] not found\n";
return join('/', $application->url($application->config()->img_url()),
$name);
}
sub param {
my ($self, $name) = @_;
my $cgi = $self->variable('cgi') or
die "template variable [cgi] not found\n";
return $cgi->param($name);
}
sub variable {
my ($self, $name) = @_;
return $self->{context}->stash()->get($name);
}
# $tparams->{img_url} = $self->url($config->img_url());
# $tparams->{css_url} = $self->url($config->css_url());
1;
|