Re: Handling array in template
Rajesh Saha <[email protected]>
| Newsgroups | gmane.comp.lang.perl.modules.template-toolkit |
|---|---|
| Message-ID | <CADoJNqDCMK2f8ZgD79M9L5pxEYm1JGFtziy_E2KXAOt7c0=Ukg@mail.gmail.com> |
Hi Chakkit, Working !! Thanks a lot !!! Regards, Rajesh On Mon, Apr 9, 2012 at 3:28 PM, Chakkit Ngamsom <[email protected]> wrote: > Hi Rajesh,**** > > ** ** > > You may try to print comma when it’s not the last element.**** > > ** ** > > [% FOREACH var IN vars %]**** > > [%- var -%][%- "," UNLESS loop.last -%]**** > > [% END %]**** > > ** ** > > Chakkit**** > > ** ** > > ===================================================**** > > iBiz Network Co., Ltd.**** > > 189/109 Soi Krungthep Kretha 7, Huamark, Bangkapi,**** > > Bangkok 10240 Thailand Tel: 0-2184-6935, Fax: 02-184-6938 > Website: http://www.ibiz.co.th, http://www.sitepackage.com**** > > ** ** > > *From:* templates-bounces-MnLy+PD7ppGDO3lXZvfOKmD2FQJk+8+b@public.gmane.org [mailto: > templates-bounces-MnLy+PD7ppGDO3lXZvfOKmD2FQJk+8+b@public.gmane.org] *On Behalf Of *Rajesh Saha > *Sent:* Monday, April 09, 2012 04:40 PM > *To:* [email protected] > *Subject:* [Templates] Handling array in template**** > > ** ** > > Hi**** > > **** > > *I want my result to be like this :***** > > **** > > abc,def**** > > **** > > *What I have done (in test.tt template file):***** > > **** > > [% FOREACH var IN vars %] > [%- var -%][%- "," -%] > [% END %]**** > > **** > > *I have processed the above test.tt through perl file like this:***** > > **** > > #!/usr/bin/perl > use Template ;**** > > $tt = Template->new(); > $file = "test.tt" ;**** > > $vars = { > vars => ["abc" ,"def"] > } ;**** > > $tt->process($file,$vars) ;**** > > *As expected, the output is:***** > > abc,def,**** > > **** > > How can I get the result the way I wanted (without the last comma) ? Help > pls.**** > > **** > > Thanks n regards**** > > Rajesh**** > > **** > > **** > _______________________________________________ templates mailing list [email protected] http://mail.template-toolkit.org/mailman/listinfo/templates