The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Template::Lace::Model::AutoTemplate - More easily find your template

SYNOPSIS

Create a template class at path $HOME/lib/MyApp/Template/List.pm

    package  MyApp::Template::List;

    use Moo;
    with 'Template::Lace::Model::AutoTemplate';

    has 'items' => (is=>'ro', required=>1);

    sub process_dom {
      my ($self, $dom) = @_;
      $dom->ol('#todos'=>$self->items);
    }

Also create an HTML file like this at $HOME/lib/MyApp/Template/list.html

    <html>
      <head>
        <title>Things To Do</title>
      </head>
      <body>
        <ol id='todos'>
          <li>What To Do?</li>
        </ol>
      </body>
    </html>

When you create an factory of the template class, we automatically load the template from the file and make it available for running transformations.

DESCRIPTION

By default we look for a string returned from a method c<template> in your class to provide the source for your generated HTML. This can be handy for small templates but often when a template is larger or when you have an HTML designer you prefer to have your templates in a stand alone file. This role will first check if you are returning something from template method and if not it will look for a file in the same directory as the template class with a name based on the class. If it finds the file it with use that as your template.

The convention for the filename of the HTML version of the template is to take the class file name, replace the '.pm' with '.html' and lowercase the name. For example if you have a class 'MyApp::Templates::User', at '$HOME/lib/MyApp/Templates/User.pm' we'd expect to find a file template at '$HOME/lib/MyApp/Templates/user.html'.

Since its generally not great practice to rely on mixed case alone to distinguish your filenames this convention should be acceptable. Your results may vary. You can override the method 'get_path_to_template' if you prefer a different lookup convention (or even hardcode a particular path).

SEE ALSO

Template::Lace.

AUTHOR

Please See Template::Lace for authorship and contributor information.

COPYRIGHT & LICENSE

Please see Template::Lace for copyright and license information.