in reply to Re: Generation of dynamically-static documents
in thread Generation of dynamically-static documents

I'm not sure I follow how having a script invoke Template::Toolkit via some custom logic to produce the data is any different than HTML::Template. In fact, I am unsure that the choice of templating system (is this the View in MVC?) is significant here, unless it's in conjunction with the underlying Controller which is dependant on some templating system to work.

I'm even less clear on how TT will help keep a single set of code with as little redundancy as possible between a static site and a CGI-based site in producing the same end-result for the browser. (The href changes I mentioned above are still the same end-result in that the links work, not that they're identical markup.)

  • Comment on Re^2: Generation of dynamically-static documents

Replies are listed 'Best First'.
Re^3: Generation of dynamically-static documents
by CountZero (Bishop) on Sep 12, 2005 at 06:04 UTC
    TT2 is quite separate from any MVC-system (although it plays very nice with Catalyst). You could run TT2 outside of a web-server (there is the ttree.pl script to do so) and it would generate all your html-pages at once -- and would even do so without re-generating the pages which remain unchanged) or run it in your web-server (CGI or mod-perl enabled Apache for instance) and the requested page(s) will be made on-the-fly.

    Perhaps that is also possible with HTML::Template, but I like TT2 more. YMMV.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re^3: Generation of dynamically-static documents
by adrianh (Chancellor) on Sep 12, 2005 at 10:01 UTC
    I'm not sure I follow how having a script invoke Template::Toolkit via some custom logic to produce the data is any different than HTML::Template

    Sure, you can do it with HTML::Template too - but TT2 has some built in tools to make the process easier. Tools like Template::Tools::ttree (comes with TT2) and Template::TT2Site will automatically generate a static copy of a TT2 site if set up appropriately. So you can have dynamically generated content on your dev site, with an appropriate ttree/rsync combo in your makefile to shift a static version of your site to the production server.

      I'm trying to figure out how ttree or TT2Site is going to figure out what code to run as part of each template. For example, one page is a list of officers in the group. So, I need to query the officers "table" via DBD::CSV, ordered by a certain value. Another page is a list of activities, grouped by month. So I need to query the activities "table", ordered and grouped - and I need to figure out the current date and only get the activities in the current "activity year" (related to the school year - starts in September). Another page is a list of these activities with descriptions and the person who runs them, which is sometimes tied to the officers. So here's a query against a couple of tables.

      These queries are already done, and they work. I just need to tie them in to the templates and either generate them statically or dynamically, depending on context. And I figured that with perl's great use of context, this would be a perfect fit ... somewhere. ;-)

      And putting code of any sort into the template wasn't exactly what I was hoping for.

        It is very easy to use DBI and such from inside a TT2-template and if all else fails you can use pure Perl in the templates.

        CountZero

        "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

        And putting code of any sort into the template wasn't exactly what I was hoping for.

        Well, I don't consider putting presentational code near the templates as a sin :-) So, to pick one of your examples, if I was looking at a TT2 solution I'd package up a TT2 Officers plugin that wrapped up all the presentation aspects of the officers and then have a template that did something like:

        [% USE Officers %] ... <table> <tr> <th>Name</th> <th>Phone</th> </tr> [% FOREACH officer = Officers.by_name %] <tr> <td>[% officer.name %]</td> <td>[% officer.phone %]</td> </tr> {% END %] </table> ...

        So the [% USE Officers %] tells the template, and therefore ttree, what code needs running. I find something like this is often a nice solution. I'm providing a clean presentation object that can't be perverted into evil business logic in the templates, and the designers can go do presentational things with Officers wherever they like without me having to touch any more code.