Re: split question
Jean-Michel Caricand <[email protected]> Mon, 18 Aug 2014 07:18:34 +0200
| Newsgroups | gmane.comp.lang.perl.modules.template-toolkit |
|---|---|
| Message-ID | <[email protected]> |
Le 17/08/2014 23:09, breno a écrit : > On Sun, Aug 17, 2014 at 4:23 PM, Jean-Michel Caricand > <[email protected]> wrote: >> Hello, >> >> I have a little question with split. I want to split my string variable on >> "." >> >> Example : >> >> >> data.className contents = "A.b.C"; >> >> [% BLOCK viewController %] >> [% items = data.className.split('\.'); >> %] >> >> [% items.last %] >> >> That doesn't work. With Perl, I can use this : >> >> @items = split(/\./, data->{className}); >> >> but that doesn't work with TT2. >> >> Any idea ? >> > Try seeing the content of your variable before the split to see if > it's really there. For instance: > > [% USE Dumper; Dumper.dump(data.className) %] > > Cheers! That works fine with : #!/usr/bin/perl use strict; use warnings; use Template; my $tt = Template->new(); my $viewController = { className => 'MyApp.view.simpledata.MyViewController', alias => 'myviewcontroller', requires => [qw/ A B C /] }; $tt->process(\*DATA, { data => $viewController }) || die $tt->error( ); __DATA__ [% USE Dumper; Dumper.dump(data.className); dir = data.className.split('\.'); %] [%- FOREACH i IN dir %] [% i %] [% END %] Ext.define('[% data.className %]', { /** * [% dir.last %] */ extend: 'Ext.app.ViewController', [% IF data.requires -%] requires: [ [%- FOREACH item IN data.requires %] '[% item %]'[% IF NOT loop.last -%],[% END -%] [% END %] ], [% END %] alias: '[% data.alias %]' }); I'm annoyed because I often use Inline :: TT in my code :-( Jean-Michel _______________________________________________ templates mailing list [email protected] http://mail.template-toolkit.org/mailman/listinfo/templates