2

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.

5
  • It might be best if you describe what goal you are trying to achieve so that we can recommend a better way to achieve it.
    – Tgr
    Commented Feb 8, 2015 at 21:42
  • @Tgr: See my answer here. I want to have the <onlyinclude> tags appear automatically, without editors having to remember to include them every time they add an infobox to a page.
    – Malvineous
    Commented Feb 11, 2015 at 2:28
  • No, I mean what you ultimately want. Store information about an article in such a way that it can be reused in the article text?
    – Tgr
    Commented Feb 11, 2015 at 2:58
  • @Tgr: I ultimately want data to be entered into infoboxes across multiple pages, and then have a summary page that lists all the pages in a table, along with information about each page in the table columns, where that content is extracted from each infobox.
    – Malvineous
    Commented Feb 11, 2015 at 3:07
  • 1
    I was just about to recommend Semantic MediaWiki but I see at the other question that you found it already. While it is possible to use native templates to build complex data structures, it is almost always a bad idea :-)
    – Tgr
    Commented Feb 15, 2015 at 7:03

2 Answers 2

1

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.

1

It's not possible to transclude partial inclusion tags, if you try that they will just sit there as plain text and do nothing. The previous answer doesn't work on MediaWiki 1.39.3 and likely on every other version.

It is possible to substitute those tags instead, however that's quite useless for regular template use.

If you want to extract data created by template calls from pages, then you will need something capable of creating databases like Extension:Semantic MediaWiki or Extension:Cargo.

If that's not an option then there is also the possibility of storing data as Categories and using one of the DynamicPageList extensions, or transcluding the entire page and extracting the data you need with pattern matching of some sort, or using Extension:Variables/Extension:Arrays with hardcoded <onlyinclude> tags on target page to "export" data from all template calls through there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.