Re: Data -> template (brain -> Perl)

Sam Tregar <[email protected]> Fri, 11 Sep 2009 11:24:22 -0400
Newsgroups gmane.comp.lang.perl.modules.html-template
Message-ID <[email protected]>
--===============4500265204439016634==
Content-Type: multipart/alternative; boundary=000e0cd5c84c18ea9504734ee94d

--000e0cd5c84c18ea9504734ee94d
Content-Type: text/plain; charset=ISO-8859-1

On Fri, Sep 11, 2009 at 11:06 AM, Robert <[email protected]> wrote:

> I am using XML::Simple to get some "simple" XML data.
>
> $template->param( DATA => sub {
>        for my $list ( @{ $data->{list} } ) {
>            print "<p>$list->{name}[0]</p><p>$list->{description}[0]</p>";
>        }
>    }
> );
>
> That prints the data to the template at the top...it doesn't go into the
> DATA var. Do I need to do the for loop outside of the $template-param?
>

Don't print() the data, instead build up a string and return() it.

-sam

--000e0cd5c84c18ea9504734ee94d
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

On Fri, Sep 11, 2009 at 11:06 AM, Robert <span dir=3D"ltr">&lt;<a href=3D"m=
ailto:[email protected]">[email protected]</a>&gt;</span> wrote:<br><div cl=
ass=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"border-left:=
 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex=
;">
I am using XML::Simple to get some &quot;simple&quot; XML data.<br>
<br>
$template-&gt;param( DATA =3D&gt; sub {<br>
 =A0 =A0 =A0 =A0for my $list ( @{ $data-&gt;{list} } ) {<br>
 =A0 =A0 =A0 =A0 =A0 =A0print &quot;&lt;p&gt;$list-&gt;{name}[0]&lt;/p&gt;&=
lt;p&gt;$list-&gt;{description}[0]&lt;/p&gt;&quot;;<br>
 =A0 =A0 =A0 =A0}<br>
 =A0 =A0}<br>
);<br>
<br>
That prints the data to the template at the top...it doesn&#39;t go into th=
e<br>
DATA var. Do I need to do the for loop outside of the $template-param?<br><=
/blockquote><div><br>Don&#39;t print() the data, instead build up a string =
and return() it.<br>
<br>-sam<br></div></div><br>

--000e0cd5c84c18ea9504734ee94d--


--===============4500265204439016634==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
--===============4500265204439016634==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Html-template-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/html-template-users

--===============4500265204439016634==--