[tw] Re: TW5 JS macros

2017-03-13 Thread tejjyid
I think I should listen to the guy here who always tells me "post code"! 1st, thanks for the new information. I hadn't previously seen the mechanism for adding default values through params; that's neat. The specific scenario I was envisaging looks a bit like this: exports.name = "demo";

[tw] Re: TW5 JS macros

2017-03-13 Thread PMario
On Monday, March 13, 2017 at 10:15:52 AM UTC+1, tejjyid wrote: > > OK, but I can accidentally return an undefined paramenter any time, > surely? > If you define your params like this. eg: exports.params = [ {"name":"tag", "default":""}, {"name":"label", "default":"<$view field='title'

[tw] Re: TW5 JS macros

2017-03-13 Thread tejjyid
OK, but I can accidentally return an undefined paramenter any time, surely? This slightly unexpected behaviour only protects against variables named in the function definition? Also, I notice Jeremy says "undefined". Thanks On Saturday, 11 March 2017 20:33:58 UTC+11, PMario wrote: > > On

Re: [tw] Re: TW5 JS macros

2017-03-11 Thread Jeremy Ruston
JS macros can specify a default value for each parameter; otherwise you'll see "undefined" as the value. For example: exports.params = [ {name: "title", "default": "My title"} ]; Note that the property name "default" must be in quotes because it is a built-in keyword. Best wishes Jeremy ---

[tw] Re: TW5 JS macros

2017-03-11 Thread PMario
On Saturday, March 11, 2017 at 6:50:06 AM UTC+1, tejjyid wrote: > > It seems that when I execute a JS macro with an unsupplied parameter, it's > set to "" rather than undefined. Is that always the case? > Yes. Macros return text and we need to be 100% compatible with wikitext macros