On Wed, Nov 9, 2011 at 5:39 AM, veeru reddy <[email protected]> wrote:

> Hi to all,
>
> I need small help in this problem, this the continuation to previous.
>
> [% FOREACH st IN university %]
> [% st.name %]
> [%st.location%]
> studentdata:
> [% FOREACH student IN st.branch.electronics.student %]
> Component type: [%+ student.name +%][%+ student.number +%]
>         [% FOREACH add IN studentaddress.adress %]
>        [% IF adress.name==student.name && adress.number ==student.number
> %]
>        [% adress.address %]
>  [% END %]
>  [% END %]
>  [% END %]
>
> by using the script I am comparing values in two keys in a hash and is
> same the get the address. I am printing  it workings but my problem is if i
> have two or three address for same student, so i placed coma and printing
> like this using this line
>
>  [% adress.address %] ,
>
> it printing    address1, address2, address3,   like that but i need to
> print like this
>
> if I have three address I need to print like this
>  address1, address2 or address3.
> if I have two address I need to print like this
>  address1, address2.
> if I have one address I need to print like this
>  address1.
>
> any body can help me in the script what should I have to do to print like
> this.
>

http://www.template-toolkit.org/docs/manual/Directives.html#section_Loop_Processing

You can use loop.last() to check whether you are on the last iteration of
the loop.  You can also use loop.size() to check how many elements there
are.  Using those will allow you to set up the output the way you want it.

Ronald
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to