Le 17/08/2014 23:09, breno a écrit :
On Sun, Aug 17, 2014 at 4:23 PM, Jean-Michel Caricand
<jean-michel.caric...@laposte.net> 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!
Hello,

I post my sample :

#! /usr/bin/perl

use strict;
use warnings;

use Inline TT => << "EO_TEMPLATE";
[% BLOCK viewController %]
[% 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 %]'
});
[% END %]
EO_TEMPLATE

my $viewController = {
    className => 'MyApp.view.simpledata.MyViewController',
    alias => 'myviewcontroller',
    requires => [qw/ A B C /]
};

print viewController( { data => $viewController } ), "\n";

My variable content is correct.

Perhaps a bug in Inline::TT ?

Thanks,

Jean-Michel

_______________________________________________
templates mailing list
templates@template-toolkit.org
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to