Re: controlling tag output order - mason newbie needs help!
Dave Rolsky <[email protected]>
| Newsgroups | gmane.comp.web.mason.devel |
|---|---|
| Message-ID | <[email protected]> |
On Tue, 27 Apr 2004, Jason Vas Dias wrote:
> I am new to Mason (though not new to PERL!) and cannot understand from
> reading the documentation or FAQ why this simple code fragment is
> outputting
> the table contents (<TR><TD>..</TD></TR>..)before the enclosing <TABLE>
> ...</TABLE> :
This is a FAQ:
http://www.masonhq.com/?FAQ:Components#h-why_does_the_order_of_output_get_mixed_up_when_i_use_print_or__r__gt_print_
Of course, the real question is why are you using print() with Mason. One
of the nice things about Mason is that you can very easily intermix text &
code fragments that generate output.
> <%perl>
> my $k;
> foreach $k ( keys %ENV )
> {
> print
> '<tr>',
> '<td>', $k,
> '</td>',"\n",
> '<td>=</td>',"\n",
> '<td>',$ENV{$k},
> '</td>', "\n",
> '</tr>',"\n";
> };
> </%perl>
This is better written this way, IMO:
% foreach my $k ( keys %END ) {
<tr><td><% $k %></td></tr>
<tr><td><% $ENV{$k} %></td></tr>
% }
There's no need for print() at all.
> I have used PHP before, and assumed Mason works in a similar way -
> evidently not !
Well, it's similar in some ways. I don't think it's really _designed_ to
be like PHP (eek, what a scary though).
As the FAQ points out, this works with Mason as of 1.10. You should
consider upgrading to the latest stable version (1.26) anyway, since if
you're just starting out there's no reason to use an older version.
But you should also consider taking advantage of Mason's strengths. One
of the main goals of a templating system is to _never_ generate blobs of
HTML in code and then spit them out. Mason makes it pretty easy to do
things the right way, I think.
-dave
/*=======================
House Absolute Consulting
www.houseabsolute.com
=======================*/
-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g.
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click