I think a cgiapp book is a great idea!  I'd be happy to help if you need
contributors, proof readers, etc.

> Ch 12:  Alternative Templating
>
> Template Toolkit and C::A::P::TT.  C::A::P::HtDot, C::A::P::PageBuilder,
> C::A::P::TemplateRunner, C::A::P::AnyTemplate

Okay, I know I'm biased, but I think that "alternate" template systems
should be featured more prominently - not just left to their own
chapter.

If nothing else, if the book is to be an advertisement to the Perl web
programming community, it had better stress right up front that Template
Toolkit is fully integrated and works right out of the box; that it's
not just an afterthought.

The cgiapp community is still split about 50:50 on HTML::Template vs.
Template Toolkit, so I don't think it's a great idea to push people
towards HTML::Template just because it's the default.

Plus, a greater percentage of the community is friendly to the "magic
dot" feature, regardless of whether the feature is used from within TT
or from within HT::Dot.

For instance, earlier this summer, a few of us were talking about making
a "template auto-filling" plugin that would pre-populate your template
params with config variables (or other data structures).  The idea is
that you could access all your config variables directly from within
your template:

    <tmpl_var config_company_name>
    <tmpl_var config_company_phone_number>

The code to flatten a config hash into your template is pretty simple,
so a plugin would only serve to document an existing "best practice".

Here's how you would do it manually:

    for my $key (keys %config) {
        $template->param("config_$key" => $config{$key});
    }

However, if you commit to flattening all your data structures before
passing them into your templates, you have to:

   (a) do a lot of work
   (b) do a lot of excessive data copying in advance
   (c) go through a lot of hoops when your data structures are more than
       one level deep (e.g. Class::DBI objects)

So as a "best practice", a number of us feel it makes more sense to pass
a reference to the entire config structure and access the data members
directly from within the template:

    $template->param('config' => \%config);

    # HTML::Template::Dot
    <tmpl_var config.company_name>
    <tmpl_var config.company_phone_number>

    # Template Toolkit
    [% config.company_name %]
    [% config.company_phone_number %]



Michael


---
Michael Graham <[EMAIL PROTECTED]>


---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/[email protected]/
              http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to