I think what you have to do is set the SFH_OBJECT_ARGS flag in the third argument of setFunctionHook.
That will change the function signature of your callback to ($parser, $frame, $args). Note that $args might no longer be an array of strings but PPNode (or something) stuff you may have to call $frame->expand() on (i think. It was something like that). This new form has a PPFrame object as a second arg. You should be able to call $frame->getParent() on it which should give you what you need. -- Brian On Monday, February 15, 2021, Yaron Koren <yaro...@gmail.com> wrote: > Hi, > > When you have a parser function called from within a template, you can of > course pass in to it any template parameters, like: > > {{#flagicon:{{{Flag image|}}} }} > > (This is a silly example, but bear with me.) I would like to instead be > able to call the parser function without the parameter, like this: > > {{#flagicon:}} > > ...and have the parser function directly get the value of the "Flag image" > parameter. > > I believe this can be done within Lua: when a Lua module is invoked from a > template, it can get the names and values of the parameters/arguments that > have been passed to that template using (I believe) code that looks like > the following: > > frame = mw.getCurrentFrame() > origArgs = frame:getParent().args > > I tried to do something similar within a parser function's code, using > various calls like the following, but nothing worked: > > $frame = $parser->getPreProcessor()->newFrame()->newChild(); > $args = $frame->getArguments(); > > Can this be done? Ideally, it would be great to get an array of all the > arguments that have been passed to the template - but just being able to > get the value for a specified parameter name would be good enough. > > -Yaron > > -- > WikiWorks · MediaWiki Consulting · http://wikiworks.com >
_______________________________________________ MediaWiki-l mailing list To unsubscribe, go to: https://lists.wikimedia.org/mailman/listinfo/mediawiki-l