Difference between revisions of "Extension:ParseAfter"

From Organic Design wiki
(notes)
 
m
Line 12: Line 12:
  
 
After the first parse, the DPL query will expand out to a number of <nowiki>{{#after}}</nowiki> expressions with resolved %TITLE% parts, these then need to be parsed separately. This is slightly tricky because each #after section needs to protect its contents from the wiki parse, yet keep the DPL variables intact so that they can be expanded properly.
 
After the first parse, the DPL query will expand out to a number of <nowiki>{{#after}}</nowiki> expressions with resolved %TITLE% parts, these then need to be parsed separately. This is slightly tricky because each #after section needs to protect its contents from the wiki parse, yet keep the DPL variables intact so that they can be expanded properly.
 +
[[Category:Extensions]]

Revision as of 01:47, 4 August 2009

Info.svg This code is in our Git repository here.

Note: If there is no information in this page about this code and it's a MediaWiki extension, there may be something at mediawiki.org.

This extension was created in response to some problems that have required inner expressions within brace structures to be parsed after the outer expressions. For example, consider the following wikitext:

{{#dpl: category = Records | format = ,*[[ :Category:{{plural|%TITLE%}} ]], \n, }}

The purpose of this is to create a list of all the record types in plural form so that a "Person" record gives a link to "Category:People". The problem is though that at the time Template:Plural is expanded, the parameter it receives (%TITLE%) is not expanded by DPL and therefore results in all pluralisation being the default operation of having an "s" appended.

The solution is to allow some parts of the expression to be parsed after the first parse is done, for example:

{{#dpl: category = Records | format = ,*{{#after: [[:Category:{{plural|%TITLE%}}]] }}, \n, }}

After the first parse, the DPL query will expand out to a number of {{#after}} expressions with resolved %TITLE% parts, these then need to be parsed separately. This is slightly tricky because each #after section needs to protect its contents from the wiki parse, yet keep the DPL variables intact so that they can be expanded properly.