|
List Info
Thread: loop.first, loop.last
|
|
| loop.first, loop.last |

|
2006-06-10 10:13:13 |
Hi,
I'm looping through an array of hashes with
"foreach" and have problems
using "loop.last":
<p>
<% foreach record in record_list %>
<% record_lastname>, <% record.firstname %><%
if not loop.last%>; <% end %>
<% end %>:
</p>
However, the Template module throws an error:
file error - parse error - pub_author.tmpl line 3:
unexpected token
(LAST) [% if not loop.last %].
The same error is thrown by "unless loop.last".
Can someone please explain this to me?
Thank you, and best regards,
Birgit Kellner
_______________________________________________
templates mailing list
templates template-toolkit.org
http://lists.template-toolkit.org/mailman/listinfo/t
emplates
|
|
| loop.first, loop.last |

|
2006-06-10 17:47:49 |
>>>>> "Birgit" == Birgit Kellner
<birgit.kellner univie.ac.at> writes:
Birgit> Hi,
Birgit> I'm looping through an array of hashes with
"foreach" and have problems using
Birgit> "loop.last":
Birgit> <p>
Birgit> <% foreach record in record_list %>
Birgit> <% record_lastname>, <% record.firstname
%><% if not loop.last%>; <% end %>
Birgit> <% end %>:
Birgit> </p>
Birgit> However, the Template module throws an error:
Birgit> file error - parse error - pub_author.tmpl line
3: unexpected token (LAST) [%
Birgit> if not loop.last %].
Birgit> The same error is thrown by "unless
loop.last".
Birgit> Can someone please explain this to me?
Unless you've done something other than just change your
delimiters
away from [% %] to <% %>, the keywords are also
(mostly) case-sensitive.
So you want things like:
<% FOREACH record IN record_list %>
etc.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. -
+1 503 777 0095
<merlyn stonehenge.com> <URL:http://www.ston
ehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy,
etc. etc.
See PerlTraining.Stonehenge.com for onsite and
open-enrollment Perl training!
_______________________________________________
templates mailing list
templates template-toolkit.org
http://lists.template-toolkit.org/mailman/listinfo/t
emplates
|
|
| loop.first, loop.last |

|
2006-06-10 22:53:28 |
Randal L. Schwartz schrieb:
>>>>>> "Birgit" == Birgit
Kellner <birgit.kellner univie.ac.at> writes:
>>>>>>
>
> Birgit> Hi,
> Birgit> I'm looping through an array of hashes with
"foreach" and have problems using
> Birgit> "loop.last":
>
> Birgit> <p>
> Birgit> <% foreach record in record_list %>
> Birgit> <% record_lastname %>, <%
record.firstname %><% if not loop.last%>; <% end
%>
> Birgit> <% end %>:
> Birgit> </p>
>
> Birgit> However, the Template module throws an
error:
> Birgit> file error - parse error - pub_author.tmpl
line 3: unexpected token (LAST) [%
> Birgit> if not loop.last %].
>
> Birgit> The same error is thrown by "unless
loop.last".
>
> Birgit> Can someone please explain this to me?
>
> Unless you've done something other than just change
your delimiters
> away from [% %] to <% %>, the keywords are also
(mostly) case-sensitive.
> So you want things like:
>
> <% FOREACH record IN record_list %>
>
> etc.
>
>
Randal,
thanks, but that's not the problem. I'm calling the module
with the
"anycase" option enabled.
$tt = Template->new( { INCLUDE_PATH =>
$vars->."/" .
"template" , TAG_STYLE => 'asp', ANYCASE
=> 1}) || die("$!");
Besides, if it were the problem, I suppose the error message
would be
different, and it wouldn't just be thrown with
"loop.last". I should add
that the same template works perfectly with
"loop.first", except that
then of course it doesn't do what I want
Birgit
_______________________________________________
templates mailing list
templates template-toolkit.org
http://lists.template-toolkit.org/mailman/listinfo/t
emplates
|
|
| loop.first, loop.last |

|
2006-06-11 01:50:22 |
Hi Birgit -
> I should add that the same template works perfectly
with "loop.first",
> except that then of course it doesn't do what I want
Sorry this does not solve the question of the
"loop.last" error message,
but if loop.first works maybe you could do something like:
<% foreach record in record_list %>
<% if not loop.first%>; <% end %><%
record_lastname %>, <% record.firstname %>
<% end %>:
Larry
_______________________________________________
templates mailing list
templates template-toolkit.org
http://lists.template-toolkit.org/mailman/listinfo/t
emplates
|
|
| loop.first, loop.last |

|
2006-06-11 08:11:42 |
Birgit Kellner wrote:
> thanks, but that's not the problem. I'm calling the
module with the
> "anycase" option enabled.
Hi Birgit,
The problem is the with the anycase option set, TT gets
confused between
the '.last' in 'loop.last' and the 'LAST' keyword. I
wasn't aware of
the problem until you mentioned it, but it does make sense.
Unfortunately the design of the parser in TT2 is such that
it can't be
fixed easily, if at all. That's one of the reasons we
totally
re-designed the parser for TT3, although that doesn't help
you now.
The only thing I can suggest is to disable the anycase
option or not use
loop.last :-(
Sorry about that. If it's any consolation I'm kicking
myself for it
right now.
A
_______________________________________________
templates mailing list
templates template-toolkit.org
http://lists.template-toolkit.org/mailman/listinfo/t
emplates
|
|
| loop.first, loop.last |

|
2006-06-11 13:40:05 |
Andy Wardley wrote:
> Birgit Kellner wrote:
>> thanks, but that's not the problem. I'm calling
the module with the
>> "anycase" option enabled.
>
> Hi Birgit,
>
> The problem is the with the anycase option set, TT gets
confused between
> the '.last' in 'loop.last' and the 'LAST'
keyword. I wasn't aware of
> the problem until you mentioned it, but it does make
sense.
>
> Unfortunately the design of the parser in TT2 is such
that it can't be
> fixed easily, if at all. That's one of the reasons we
totally
> re-designed the parser for TT3, although that doesn't
help you now.
>
> The only thing I can suggest is to disable the anycase
option or not use
> loop.last :-(
What about making an alias? loop.final?
_______________________________________________
templates mailing list
templates template-toolkit.org
http://lists.template-toolkit.org/mailman/listinfo/t
emplates
|
|
| loop.first, loop.last |

|
2006-06-11 23:38:07 |
Stuart Johnston wrote:
> Andy Wardley wrote:
>> Birgit Kellner wrote:
>>> thanks, but that's not the problem. I'm
calling the module with the
>>> "anycase" option enabled.
>>
>> Hi Birgit,
>>
>> The problem is the with the anycase option set, TT
gets confused
>> between the '.last' in 'loop.last' and the
'LAST' keyword. I wasn't
>> aware of the problem until you mentioned it, but it
does make sense.
>>
>> Unfortunately the design of the parser in TT2 is
such that it can't be
>> fixed easily, if at all. That's one of the
reasons we totally
>> re-designed the parser for TT3, although that
doesn't help you now.
>>
>> The only thing I can suggest is to disable the
anycase option or not
>> use loop.last :-(
>
> What about making an alias? loop.final?
That seems like a good idea.
:Robert
_______________________________________________
templates mailing list
templates template-toolkit.org
http://lists.template-toolkit.org/mailman/listinfo/t
emplates
|
|
[1-7]
|
|