Mobile app version of vmapp.org
Login or Join
Sent6035632

: How to transclude in MediaWiki template? I have a MediaWiki template that I want to use in other templates, but I want the first template to add <onlyinclude> tags to the other templates

@Sent6035632

Posted in: #Mediawiki

I have a MediaWiki template that I want to use in other templates, but I want the first template to add <onlyinclude> tags to the other templates it gets used in.

Unfortunately these tags get processed on the first template, so they ever get included in the target template.

How can this be done?

Example:


TemplateA: content is <onlyinclude>{{{1}}}</onlyinclude>
Article1: Article 1 {{TemplateA|Hello}}
Article2: Article 2 can say {{:Article1}}


I would like this to appear as:


Article1: Article 1 content is Hello
Article2: Article 2 can say Hello


The problem is the <onlyinclude> tags get processed on TemplateA whereas I want them to get passed through to Article1 and processed on Article1 instead.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Sent6035632

1 Comments

Sorted by latest first Latest Oldest Best

 

@Heady270

This little trick should work since the noinclude is applied on the first generation and then the onlyinclude gets only processed at the second parsing.

<only<noinclude></noinclude>include>{{{1}}}</only<noinclude></noinclude>include>


This needs to be tested (I don't have a test Mediawiki anymore) and it might not work on all Mediawiki versions.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme