[ic] Passing parameters to usertags
Paul Jordan
interchange-users@icdevgroup.org
Mon May 26 11:53:01 2003
> I'm having some trouble with (what I think is) a very basic
> question
> on a custom usertag. I have the following tag, which I am constructing
> to dynamically build a navbar on an IC 4.9.7 site. The problem I am
> having is getting parameters passed to the subroutine. I thought if I
> wanted to access a section of the web site called "search" under a page
> called "database" (where "section" and "page" are just terms I'm using
> to describe different parts of my site) I could do something like
>
> [test_nav page=database section=search]
>
> and have the variables $page and $section be accessible to me, but that
> doesn't appear to work.
>
> So instead, I started calling my tag with positional
> parameters, like
> so:
>
> [test_nav database search]
>
> This works, sort of. I am able to shift arguments off the @_
> variable, but everything after the tag name (eg: "database search")
> gets pulled off as one variable, whereas I expected this to come off as
> a list. In my subroutine, I thought I could do
>
> my ($page, $section) = @_;
>
> but that doesn't work, and instead I have to do the following:
>
> UserTag test_nav Interpolate
> UserTag test_nav Routine <<ENDTEST
> sub {
> my $nav;
> my $page;
> my $section;
> my $args = shift; # Gets arguments that were
> passed, as a single
> string?
> ($section, $page) = split / /, $args;
>
> # do stuff with $section and $page...
>
> }
> ENDTEST
Try:
UserTag test_nav Order page section
UserTag test_nav Routine <<EOR
sub {
my ($page, $section) = @_;
my $nav;
........ rest of it
There are many usrtags present already that can give you hints too.
Paul