>>>>> "AS" == Aaron Sherman <[EMAIL PROTECTED]> writes:
AS> 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.
AS> Template Toolkit makes this trivial. The "code" that you put in the
AS> template is a pseudo-code that has only the tools you need in order to
AS> integrate your variables with the page. The code all goes elsewhere. For
AS> example, here's some CGI:
i know it can do that. but i have been rolling my own for so long (most
basic templating needs are simple) that i just extended it in various
ways.
note that in my little hack if a chunk is expanded and its name is a
list in the data, it will loop for you. if the data is a single hash ref
it will just expand it using that name. so the data tree can actually
driive the expansion. you could use this for a very simple if construct
by wrapping the conditional text in chunk markers and then either
putting a hash ref to use the text or missing to skip it. anyhow i am
not saying my hack is a replacement for tt but it does an awful lot of
templating stuff in 3 tiny subs. i am just showing that basic and
powerful templating doesn't need a super large and massively featured
module. this project i am doing does need all those features and
reinventing them all would take tons of work. but for the little
templating stuff i do now and again, i like to roll my own.
AS> Notice that while there's a loop in the template, it's nothing but a
AS> simple iteration, and there's no complex flow control here. Thus, an
AS> HTML editing tool could display this with a reasonable degree of
AS> non-intrusiveness and allow you to change that to a table:
AS> <html><head><title>[% stuff %]</title></head>
AS> <body>
AS> [% FOREACH n = nums; %]
AS> <p>Say hello to the number [% n %]</p>
AS> [% END %]
AS> </body>
AS> </html>
i keep the loops implied in the data. you only need to mark a chunk for
expansion and it gets looped if the data is an array ref. you don't even
need special loop template markup. :)
AS> <table>
AS> [% FOREACH n = nums; %]
AS> <tr><td>Say hello to the number</td>
AS> <td>[% n %]</td></tr>
AS> [% END %]
AS> </table>
and in my little hack you have it even simpler:
<html><head><title>[% STUFF %]</title></head>
<body>
[%CHUNK_NUM%]
<p>Say hello to the number [% N %]</p>
[% END_NUM %]
</body>
</html>
the code would have to build a list of hashes like this:
$data->{NUM} = map { N => $_ }, @{$data->{nums}} ;
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:
same with my style. templating is not rocket science. that is why there
are so many template modules on cpan. they are trivial to do basic
versions. whether they mature into large systems like tt2 is another
matter.
AS> This is the way content and code should be combined... anything more
AS> complex than the above should be used to construct the variables.
please restate that last sentence in english. i think we are agreeing
but i can't be for sure! :)
uri
--
Uri Guttman ------ [EMAIL PROTECTED] -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm