> From: "pm5" <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> Date: Wed, 6 Aug 2003 17:23:18 +0800
> Subject: [Templates] Parsing text by template
...
> For example, given the following plaintext (foo.txt):
>     Hello, Peggy.  You have 2 messages:
>       Liz     Re: the program you asked
>       Alice   I GOT IT!!!

> And the following template (foo.tpl):
>     Hello, [% name %].  You have [% messages.length %] messages:
>     [% FOREACH m=messages %]
>       [% m.sender_name %]     [% m.subject %]
>     [% END %]


You could extract delimited data from a text file with Datafile, as
documented below.  and figure out the number of messages in the
calling template automatically.

    Datafile

    Provides an interface to data stored in a plain text file in a simple
    delimited format. The first line in the file specifies field names
    which should be delimiter by any non-word character
    sequence. Subsequent lines define data using the same delimiter as int
    he first line. Blank lines and comments (lines starting '#') are
    ignored. See Template::Plugin::Datafile for further details.

    /tmp/mydata:

        # define names for each field
        id : email : name : tel
        # here's the data
        fred : [EMAIL PROTECTED] : Fred Smith : 555-1234
        bill : [EMAIL PROTECTED] : Bill White : 555-5678

    example:

        [% USE userlist = datafile('/tmp/mydata') %]

        [% FOREACH user = userlist %]
           [% user.name %] ([% user.id %])
        [% END %]

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Richard Tietjen <[EMAIL PROTECTED]>       www.pobox.com/~rdtietjen
          "Irony is what they make two-edged swords from."


_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to