Search code examples
mediawikimediawiki-templates

How do I insert tables inside infoboxes on Wikia pages?


I want to insert tables in infoboxes. For example, I have a proteinbox I've developed using the infobox template (http://health-and-medicine.wikia.com/wiki/Template:Proteinbox), and its FASTA field is too large to fit comfortably in the proteinbox. Hence I would like it to be a collapsible table inside the box.

This is what I tried:

{{infobox
 | Row 1 = 
  {| class = "mw-collapsible mw-collapsed wikitable"
  |-
  | <!-- Some table content -->
  |}
}}

Solution

  • Your problem is, that you are putting the nested table inside a template. The pipe characters (|) in the table syntax then collides with the pipe usage in templates.

    The most commonly used hack to get around this is to create a template called Template:!, simply containing only the pipe character, and then use that when you need to put tables, parser functions or other stuff using pipe characters, inside templates. Your table would then look like this (with every | replaced by {{!}}):

    {{{!}}
    {{!}}-
    {{!}} A1
    {{!}} B1
    {{!}}-
    {{!}} A2
    {{!}} B2
    {{!}}}
    

    ...the equivalent of

    {|
    |-
    | A1
    | B1
    |-
    | A2
    | B2
    |}
    

    Furthermore, you have to assure that the table starts at a new line, as blank lines are stripped from template parameters. The easiest way is to add an empty <nowiki /> tag. The code in your question would then look like this:

    {{infobox
     | Row 1 = <nowiki />
      {{{!}} class = "mw-collapsible mw-collapsed wikitable"
      {{!}}-
      {{!}} <!-- Some table content -->
      {{!}}}
    }}
    

    In recent versions of MediaWiki, the {{!}} syntax is added to the software, but on Wikia, as of 2017, this needs to be added to a template.