Looking to hire a Perl programmer?

Serving Catalyst::View::TT templates from a DBIC model

Following yesterday’s release of Template::Provider::DBIC I wanted to write a quick tutorial describing how to deploy it in your Catalyst projects.

Create your schema

The minimal DBIx::Class::Schema required to store your templates is as follows…

package MyApp::Schema::Template;
use base qw/ DBIx::Class /;

__PACKAGE__->load_components( 'PK::Auto', 'Core' );

    'name',     { data_type = 'VARCHAR', size => 4 },
    'modified', { data_type = 'DATETIME'           },
    'content',  { data_type = 'TEXT'               },

__PACKAGE__->add_unique_constraint( 'name', ['name'] );


Create your view

The Template Toolkit lets you specify providers through the LOAD_TEMPLATES configuration option…

package MyApp::View::TT;

use base qw/ Catalyst::View::TT /;
use Template::Provider::DBIC::Schema;

            RESULTSET => MyApp->model('Template'),


You’re now using DBIx::Class for your templates

Congratulations! The Template::Provider::DBIC documentation contains further details about configuration options, use with other providers, and serving templates from multiple ResultSets.

Back to UK Perl Programmer.

Dave Cardwell (G+ | Tw | LI | GH) :: Sitemap