Generally, a valid perl variable is a valid template toolkit variable.
- The variable should always start with a non numeric, non symbolic character
[ A to Z and _ ]
- Variable can only contain
a to z
,0 to 9
and_
(underscore) characters. - Variable names cannot contain special symbols (it includes
'-'
symbol ).
Eg:
$user-name
is not a valid perl variable. but
$user_name
is valid.
Here is what perl interpreter throws for your code
$ my $user = { user-name => "John" };
Compile error: Bareword "user" not allowed while "strict subs" in use at (eval 294) line 5.
If you really want to use 'user-name'
then you should define like this
$ my $user = { "user-name" => "John" };
$ my $data = { user => $user };
And you should access it in your tt2 file like this:
[% user.item('user-name') %]