> [% adashb = 'a-b' %]
> [% USE bar = url ("http://no.where.com";, arg1 => 'arg2', $adashb => 2) %]
> Why does this end up without replacing adashb? [% bar %]

The parser currently only allows simple literals (quoted strings
without interpolation) and identifiers (plain variable names) in
the key (left-hand-side) of hashes and function parameters.  v3
also suffers from the same problem.

Here are two different fixes: a workaround and a patch.  Take your
pick.

  - build the argument hash manually:

    [% adashb = 'a-b' %]
    [% args = {}; args.arg1 = 'arg2'; args.$adashb => 2; %]
    [% USE bar = url ("http://no.where.com";, args) %]
    This does replace adashb... [% bar %]

  - apply the one-line patch below.  This allows $var and ${var}
    to also be used as keys in hashes.  After you apply the patch
    you need to run "yc" in Template-Toolkit-2.04/parser.  Then
    redo make, make test and make install.

    With the patch your example should work without changes.

Craig

--- Template-Toolkit-2.04/parser/Parser.yp        Mon Jun 25 03:55:07 2001
+++ new/parser/Parser.yp   Mon Aug 13 09:56:50 2001
@@ -326,7 +326,7 @@
 #      |   IDENT ASSIGN term       { "'$_[1]' => $_[3]"                  }
 #;
 param:     LITERAL ASSIGN expr     { "$_[1] => $_[3]"                    }
-       |   IDENT ASSIGN expr       { "'$_[1]' => $_[3]"                  }
+       |   item ASSIGN expr        { "$_[1] => $_[3]"                    }
 ;
 
 ident:      ident DOT node         { push(@{$_[1]}, @{$_[3]}); $_[1]     }



Reply via email to