6

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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Regis May
  • 3,070
  • 2
  • 30
  • 51

1 Answers1

9

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.

Sam Wilson
  • 4,402
  • 4
  • 29
  • 30
  • FYI: In consequence to your suggestion I experimented with an alternative MW-plugin "SimpleTable" as it seemed even better suitable for that purpose. Unfortunately that particular plugin did not expand parameters passed to the template. Instead of doing even more research and maybe adapting the SimpleTable plugin I decided to go with a different approach: Define a subpage for the purpose at hand and design the template in such a way that it automatically includes that subpage. Nevertheless thanks a lot as I learned quite a bit about MW form your answer. – Regis May Oct 02 '17 at 08:09