> Can anyone tell me how to pass named parameters into a macro and use them to
> define variables?  What I'm looking to do is define a macro like so:
> > <<macroName parameter1:"value1" parameter2:"value2" parameter3:"value3">>
> And then use that values in my macro, as JS variables.
> > var variable1 = getParam(params,"parameter1","");
> ... to no avail.  I suspect there's a simple syntax error at play, but I
> can't tell what it is.
> Does anyone have a moment to set me straight on how the getParam function
> works — or point me toward some helpful documentation?  :)

The arguments to the macro's handler function including *two* ways to
access the macro parameters:

1) 'params' is an array of text strings.  It is generated by the
TWCore macro processor by applying the .readBracketedList() method to
the text of the space-separated macro parameters.  Thus, the items in
the params array are simple *positional* parameters.  For example:
   <<macroName foo bar baz mumble>>
results in:
   params[0]="foo"
   params[1]="bar"
   params[2]="baz"
   params[3]="mumble"

2) 'paramString' is a single piece of text containing the complete
parameter text, exactly as entered into the macro:
   <<macroName foo bar baz mumble>>
results in:
   paramString="foo bar baz mumble"

Note that in (1), if you use a *named* parameter, e.g.:
   <<macroName foo bar something:baz mumble>>
the result is:
   params[0]="foo"
   params[1]="bar"
   params[2]="something:baz"
   params[3]="mumble"
i.e., the *name* is NOT processed separately as is treated as part of
the value.  To get the *named* parameter values, you need to run the
paramString through a method called .parseParams:
   var parsed=paramString.parseParams('anon',null,true,false,false);

This results in a structured object containing information about the
parameters.  Then, to extracdt a specific parameter value by name, you
write:
   var myVar=getParam(parsed,'paramname','defaultvalue');

enjoy,
-e
Eric Shulman
TiddlyTools / ELS Design Studios
----------
Was this answer useful? If so, please help support TiddlyTools:

   TiddlyTools direct contributions: (paypal)
      http://www.TiddlyTools.com/#Donate
   UnaMesa tax-deductible contributions:
      http://about.unamesa.org/Participate (paypal)
   TiddlyWiki consulting:
      http://www.TiddlyTools.com/#ELSDesignStudios
      http://www.TiddlyTools.com/#Contact



Instead, to extract *named* parameters, you use the paramString

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/tiddlywiki?hl=en.

Reply via email to