$string = "test,ok,me"
1
2
3
4
5
6
[% FOREACH key IN string.split(',') %]
<tr>
<td>[% key %]</td>
<td><input type="text" name="[% key %]" size="20" class="formulartext" value="" id="input"></td>
</tr>
[% END %]
2014-06-14T13:17:10 tino91DEalso weder [% $lang_$key %] noch [% lang_$key %] haben hier geklappt.
2014-06-14T13:44:28 pqgenau, nur mit tags drumherum:
funktioniert hier.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
use strict; use warnings; use Template; my $config = {}; my $tt = Template->new($config); my $input = "foo.tt"; my $vars = { lang => { de => { "ok" => "Okay", }, en => { "ok" => "Ok", }, }, language => "lang_de", }; $tt->process($input, $vars) or die $tt->error(); __END__ foo.tt: [% code = "ok" %] [% mylang = language.substr(5) %] [% lang.$mylang.$code %]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
use CGI::Carp qw(fatalsToBrowser); use CGI ':standard'; use strict; my %lang; $lang{"ok"}{"de"} = "OK"; $lang{"saved"}{"de"} = "Speichern erfolgreich. "; $lang{"ok"}{"en"} = "OK"; $lang{"saved"}{"en"} = "Saved!"; # Ist sonst dynamisch $sesslang = "de"; # Sprache einbinden for (keys %lang) { #print "Add $_ with $lang{$_}{$sesslang} for Sessionlang $sesslang <br>"; $vars{"lang_$_"} = $lang{$_}->{$sesslang}; } $tt->process($Template, \%vars ) || die "Template process failed: ", $tt->error(), "\n";