On Tue, 2005-01-18 at 12:07, Uri Guttman wrote:
> >>>>> "DB" == Dan Boger <[EMAIL PROTECTED]> writes:

>   DB> I've been trying to be good, and seperate content from presentation.
>   DB> But since starting using Mason, I find that's much harder to do?  Yes

> in the templating world, there are two camps, code embedded in the text
> and code separated from the text. i have always been in the code outside
> the text camp and i have rolled my own tiny templaters in that way for
> years.

Template Toolkit makes this trivial. The "code" that you put in the
template is a pseudo-code that has only the tools you need in order to
integrate your variables with the page. The code all goes elsewhere. For
example, here's some CGI:

        use CGI qw(:standard);
        use Template;
        
        my $stuff=param('stuff');
        my $ttk = Template->new()
                or die "Failed to instantiate TTK engine";
        print header();
        $|=1;
        $ttk->process('mytemplate.tt',
                { stuff => $stuff, nums => [1,2,3] })
                or die "Cannot process template 'stuff'";
        exit 0;

And a template:

        <html><head><title>[% stuff %]</title></head>
        <body>
        [% FOREACH n = nums; %]
        <p>Say hello to the number [% n %]</p>
        [% END %]
        </body>
        </html>

Notice that while there's a loop in the template, it's nothing but a
simple iteration, and there's no complex flow control here. Thus, an
HTML editing tool could display this with a reasonable degree of
non-intrusiveness and allow you to change that to a table:

        <table>
        [% FOREACH n = nums; %]
        <tr><td>Say hello to the number</td>
        <td>[% n %]</td></tr>
        [% END %]
        </table>

This is the way content and code should be combined... anything more
complex than the above should be used to construct the variables. The
only exception is conditional includes, which are a nice way to
conditionally insert an entire section of a page, based on the setting
of a variable without having to put HTML in your variables (e.g. "are
you loogged in? Ok, you get the 'log out/manage my account' sidebar.")

-- 
â 781-324-3772
â [EMAIL PROTECTED]
â http://www.ajs.com/~ajs

 
_______________________________________________
Boston-pm mailing list
Boston-pm@mail.pm.org
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to