[Templates] csv file to template data file
Rick
wrinkles at gmail.com
Mon Mar 10 18:07:20 GMT 2008
Currently I'm creating the $csv_data by running the above perl script from
the command line. Then I'm using ttree to process the templates. I know this
is awkward, which is why I posted here.
I think that I should call the perl script from within TT2, creating
$csv_data which can then be used by other templates. Is that right? If so,
what is the best way to call a perl script from TT2? Also, if I then run
that script and generate $csv_data from within a preprocessed template, is
that data accessible to other templates?
Hoping I'm making sense...
Rick
On Mon, Mar 10, 2008 at 9:12 AM, Jonathan Rockway <jon at jrock.us> wrote:
> * On Mon, Mar 10 2008, Rick wrote:
> > Hi all. I'm kinda new to TT2, perl, and programming. My first perl
> script was
> > required to read a csv file (from an excel spreadsheet) and write to a
> template
> > with the corresponding data structure (an array of arrays), which I
> could then
> > preprocess and access from other templates. The following script worked
> just
> > fine. However, I would appreciate comments on other (better) ways to
> accomplish
> > the same purpose, either in perl or within TT2 itself. (Any perl wisdom
> > appreciated). Thanks.
>
> I'm confused as to why you're dynamically generating the template. The
> template should be a static entity you pass data to:
>
> my $csv_data = [ [ 'foo', 'bar', 'baz' ], ['a', 'b', 'c'] ];
>
> And then:
>
> [% FOREACH row IN csv_data %] # row = [qw/foo bar baz/] and then [qw/a
> b c/]
> <tr>
> [% FOREACH column IN row %] # column = 'foo', then 'bar', ...
> <td>[% column | html %]</td>
> [% END %]
> </tr>
> [% END %]
>
> Regards,
> Jonathan Rockway
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.template-toolkit.org/pipermail/templates/attachments/20080310/cf9821d2/attachment.htm
More information about the templates
mailing list