Hi Steve,
I think I see what you're getting at, however I'm not sure that it addresses the original request:
But how can I get the parser to parse the contents of the tag before calling the according extension callback function?
It would seem to me that what he's looking for is <tag>{{{param}}}</tag> to execute in such a way that {{{param}}} is translated _before_ it even gets to the tag's implementation method.
For example, say you have Template:Whatever, which contains:
<tag>{{{1}}}</tag>
And you call it like so:
{{Whatever|something}}
The internals of <tag> will always receive "{{{1}}}", not "something" - which I believe is Nils original complaint.
So although you're correct that it's possible to grab the Parser reference and force it to parse the internal text as was provided to the tag, this doesn't account for (what I believe to be) the original question.
Also, (not sure who said the following):
Parser functions don't substitute template arguments either. To do that you'd have to get the argument array from the call, call $parser->createAssocArgs($args) to parse it, and return the result
Well, ok. Technically speaking, the parser function itself is not "parsing" the {{{params}}}. However, the Parser class does translate these params to the appropriate string values prior to executing a parser function - which achieves what Nils was originally aiming to do.
-- Jim
On 6/7/07, Steve Sanbeg ssanbeg@ask.com wrote:
On Wed, 06 Jun 2007 14:36:19 -0500, Jim Wilson wrote:
Or you could parse the content before doing anything with the <tag> content. One of the hook parameters is the parser you should use to replace templates.
I think he's talking about params like {{{1}}}, not processing a transclusion request {{like this}}. But even so, a parser function is a more elegant solution to either of these as it happens "in line" with
all
the benefits of being integrated into the parser during that earlier
pass.
Extension tags happen "outside" template processing, so mixing the two
is
kind of a strange thing in practice.
Extension tags are supposed to return HTML, and don't necessarily have wiki input. If they have wiki text, they can use $parser->recursiveTagParse() to parse it.
If you just want to substitute parameters in a tag function, you'd need to pass arguments to the tag, then replace them in the text i.e.
<tag param=val> text {{{param}}} </tag>
function MyTag ($in, $params, $parser) { $text = $parser->replaceVariables($in,$params); ...
Which wouldn't parse, just replace the args with a (techincally private) parser method.
To parse arguments from a parser function, you'd only need to return an array of arguments and the right combination of flags to parse them.
-- Jim
On 6/6/07, Platonides Platonides@gmail.com wrote:
Parser functions don't substitute template arguments either. To do that
you'd have to get the argument array from the call, call $parser->createAssocArgs($args) to parse it, and return the result
Jim Wilson wrote:
Hi Nils,
Two things:
- You're correct that extension tags don't expand template
parameters.
What you'd want is what's called a parser function [1] [2].
- You may want to have a look at Semantic Forms - there's a chance
it
may
already do what you want (or perhaps at least a portion thereof) [3].
Or you could parse the content before doing anything with the <tag> content. One of the hook parameters is the parser you should use to replace templates. See mediawiki-l archives.
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/wikitech-l
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org http://lists.wikimedia.org/mailman/listinfo/wikitech-l