Search code examples
csvmediawikimediawiki-templates

How can I pass some MediaWiki markup (here: a table) to a template?


I'm looking for a way that a user may specify a table - i.e. by specifying it in MediaWiki syntax - to a template. The template should then put this table in the context of some larger output provided by the template.

A simple example. Is there a way a user could specify something like this:

{{MyTemplate
|FooBar
|{| class="wikitable"
| Something
|-
| Useful
|}
}}

and then the template outputs somewhere the specified data FooBar and the table?

If this doesn't work, is there some alternative way of doing this? i.e. by specifying some arbitrary (!) CSV data and outputting it in a formatted way?


Solution

  • The reason it doesn't work is that the pipes in the table are seen by the template as parameter delimiters. The {{!}} magic word exists as a workaround to this, so your example could be done like this:

    {{MyTemplate
    |FooBar
    |{{{!}} class="wikitable"
    {{!}} Something
    {{!}}-
    {{!}} Useful
    {{!}}}
    }}
    

    This does make it rather less readable though!

    As for rendering CSV data as a table, the TableData extension may do what you're looking for.