In a custom wiki based on MediaWiki installation 1.29, I would like to include an example in a template page.
To include this example I want both to print the code of the template and to show it. So I need to write the text down two times: one surrounded by the <pre>
tag to show the text and the other one in plain text to show the interpreted example.
In order the maintain the text once only, I thought about inserting the example in a subpage like this <pre>{{SomeTemplate|SomeParameter}}</pre>
and transclude this text to show it in the instruction page.
So, for the code I simply transclude {{/subpage}}
while for the actual template to be shown my plan was to replace <pre></pre>
with an empty string using the #replace
function from https://www.mediawiki.org/wiki/Extension:ParserFunctions .
The first part worked flawlessly, the second one I am unable to make it work. The code I use for the replacement is
{{#replace:{{#replace:{{/subpage}}|<nowiki><pre></nowiki>|}}|<nowiki></pre></nowiki>|}}
But this always returns an empty string. In fact, even the part
{{#replace:{{/subpage}}|<nowiki><pre></nowiki>|}}
returns the same empty string.
Interesting enough, even the code
{{#replace:<nowiki><pre>{{SomeTemplate|SomeParameter}}</pre></nowiki>|<nowiki><pre></nowiki>|}}
returns nothing.
Is my plan feasible and I am doing something wrong in the syntax, or is it conceptually wrong and never going to work?
Thanks
Luca
After much research i found I was approaching the problem from the wrong angle.
I discovered (here https://www.mediawiki.org/wiki/Help:Templates#Usage) that the prefix msgnw:
allows to transclude the text of a template without invoking it.
So the easisest way to accomplish my goal is to create a subpage with only the code, without the <pre>
and then using:
<code>{{msgnw:/Subpage}}</code>
to show the underlying code, and
{{/Subpage}}
to show the example.