2009/11/4 Josh Rosenbaum <j...@infogears.com>:
> Dermot wrote:
>>
>> I have used $ with reference to
>>
>> http://template-toolkit.org/docs/manual/Variables.html#section_Variable_Interpolation
>> but if I mis-reading the docs please let me know.
>
>
> You are misreading them. Use:
>
> [% subs.makeLink(lid=>lightbox.lid, perpage=>p) %]
>
> However, if you need this passed in list form, you'll need to do something
> different. TT takes named parameters and puts them in a hashref that it
> passes at the end of the parameters for a routine. So technically the above
> is the same as doing:
> [% subs.makeLink( {lid=>lightbox.lid, perpage=>p } ) %]
>
> Here is info on named parameters in TT:
> http://docs.huihoo.com/template-toolkit/Manual/Variables.html#Parameters_and_Return_Values
>
>
> So you may need to use this instead if your subroutine is not expecting a
> hashref:
> [% subs.makeLink('lid', lightbox.lid, 'perpage', p) %]
>
>
> You should really only use $ in places where TT is expecting a string:
> *) inside a string. ie. "Here $test".
>
> *) Using PROCESS/INSERT, because they normally consider their file parameter
> a string. [% PROCESS filename %] vs [% PROCESS $get_filename_from_me %]
>
> *) in a hash you want to get the key to access from a varaible. [% hash.key
> %] vs [% hash.$get_key_from_me %]

Thanx, I'll try and absorb that.

I'm getting closer to the answer. I can see what's happening but I
struggled to get at the hash. I got there in the end,

sub someFunc {
    use Data::Dumper;
    print STDERR Dumper(@_);
    print STDERR "Last el=". ref($_[-1])."\n";
    my $args = (ref($_[-1]) eq 'HASH') ? pop : @_;
    foreach (keys %{$args}) {
        print STDERR "someFunc: $args->{$_} => $_\n";
    }
}


$VAR1 = {
          'lid' => '69264',
          'perpage' => 24
        };
Last el=HASH
someFunc: 69264 => lid
someFunc: 24 => perpage
$VAR1 = {
          'lid' => '69264',
          'perpage' => 48
        };
Last el=HASH
someFunc: 69264 => lid
someFunc: 48 => perpage
$VAR1 = {
          'lid' => '69264',
          'perpage' => 96
        };
Last el=HASH
someFunc: 69264 => lid
someFunc: 96 => perpage

I have a problem now in that the function is used elsewhere but called as
SomeMod::someFunc(lid=>$lid, perpage=>'12').

I want to maintain that compatibility. I'll need to coerce the
reference into an normal hash or vice-verse. I guess that's a question
for another list.

Thanx for all the help though,
Dp.

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

Reply via email to