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 -->
|}
}}
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.
Just as further information to Leo's answer above (i unfortunately can't comment yet), please note that {{!}} is a magic word in MediaWiki now and needs template no more.
Please refer to https://www.mediawiki.org/wiki/Template:! and https://gerrit.wikimedia.org/r/#/c/136234/ for details on this modification in MW.
Related
Let's say i have a template in my MediaWiki like
<includeonly>
<div id="custom-person">
* <span>Birthday:</span> {{#if: {{{birth date|}}} | <b>{{#ol-time:|{{{birth date}}}}}</b> | — }}
{{#if: {{{full name|}}} | * <span>full name:</span> <b>{{{full name}}}</b>}}
{{#if: {{{birth place|}}} | * <span>birth place:</span> <b>{{{birth place}}}</b>}}
{{#if: {{{age|}}} | * <span> age:</span> <b>{{{age}}}</b>}}
{{#if: {{{nationality|}}} | * <span> nationality:</span> <b>{{{nationality}}}</b>}}
<div class="clear"></div>
</div>
[[Category:Person]]
__NOTOC__
</includeonly>
All these pages are in one Namespace (0).
I need to generate head meta tags with data from this template.
I figured out how to filter such a pages and add title tags in my SkinPerson.php
if ( $out->getTitle()->getNamespace() == 0 ) {
$out->addMeta( "description", $out->getPageTitle());
$out->addHeadItem( 'og:description', '<meta property="og:description" content="' . $out->getPageTitle() . '">');
}
But I'm really stuck on how can I insert in, say, 'og:description' tag something like {{{full name}}} + {{{age}}} ?
That's simply not possible, and I would wonder what your use case here would be, why you want to do that. First some explanation, why this is not possible in the way you want to achieve that:
The template is evaluated by a piece of software we call the Parser. The parser is generating a html representation of your wikitext, including all the templates and so on. The result of that is then saved in the ParserOutput and probably cached in ParserCache (so that not every time it needs to be parsed again).
However, the skin, where you want to add the head item, is using the output of the parser directly, so it does not really know about the wikitext (including template parameters) anymore, and really shouldn't.
One possible solution for what you want to achieve is probably to extend the wikitext markup language by providing a tag extension, parsing that during the parsing of the wikitext, and save the values for the head items in the database. During the output of the page you can then retrieve these values from the database again and add them into the head items like you want. See more information about that in the documentation.
There might be other ways, apart from the database, to get information from the parsing time into the output time, which I'm not aware of.
setting up documentation for a plugin.
Can you add tables within a dd tag?
I tried the code below but it wont output as a table I tried with the double space line break technique but nothing either
This doesnt parse the table and just leaves the table syntax as is
Term
: definition
: | Table cell | Table cel | Table cell |
This wont render (note there are two spaces after definition)
Term
: definition
| Table cell | Table cel | Table cell |
my goal is this:
<dl>
<dt>Term</dt>
<dd>
definition
<table>
<!-- table rows and cells here -->
</table>
</dd>
</dl>
Depending on the Markdown implementation you are using either you can't or you need to do three things:
(1) Wrap your table with blank lines
A table is a block level element, just like a paragraph is. Therefore, it needs to be on a line by itself. To accomplish that, you need to include a blank line before the table. There is no need to add two spaces to the preceding line as the blank line already separates the elements and each block-level element will always be on its own line (barring some non-standard CSS which changes that behavior) .
(2) Indent your table
Of course, when you are nesting block level elements inside a list item and those elements do not start in the first line of the list item, you must indent those elements by one level to indicate they are nested. Therefore, the table must be indented by four spaces or one tab.
(3) Add a table header
Except for Kramdown, all implementations which support tables (that I am aware of) require the table to include a header. Otherwise, they do not recognize it as a table.
Example
Try this:
Term
: definition
| Header 1 | Header 2 | Header 3 |
| ---------- | --------- | ---------- |
| Table cell | Table cel | Table cell |
That said, both definition lists and tables are non-standard Markdown and their behavior varies among implementations which support them (not all do). Therefore, YMMV.
In fact, Babelmark demonstrates that the above works for Pandoc, RDiscount, PHP Markdown Extra, and MultiMarkdown (strangely version 5, but not version 6). Note that a few other implementations likely would work as well if they were properly configured. Babelmark only demonstrates default behavior for each implementation.
I need an inline query that lists all pages from a specific namespace, but without listing subobjects specified on these pages.
Restricting results to a namespace is possible like that:
{{#ask: [[ExampleNamespace:+]] }}
But it lists all subobjects, too.
Workarounds:
Specify a category on these pages (subobjects don’t inherit it) and query for the category instead:
{{#ask: [[ExampleCategory]] }}
Specify a property on these pages (and never on the subobjects) and query for the property (with a wildcard value) instead:
{{#ask: [[ExampleProperty::+]] }}
But both workarounds require editing, which I would like to avoid. Is there a better way to solve this?
Not sure if it's a better way, but it looks like array formats/arrays and their #arraymap and #arrayunique functions are a way to go in order to trim SMW subobject tags and make the DISTINCT operation. Unfortunately, the solution below has a query result limit issue described as well (at least out of what I understand in SMW). In general, it may look like the following, and I will appreciate if someone suggests a nicer solution:
<!-- Fetch all pages from the "Live event" namespace -->
{{#arraydefine: QUERY_RESULT
| {{#ask: [[Live event:+]]
| format = array
| link = none <!-- NOTE: array item link -->
| limit = 10000 <!-- NOTE: limit -->
}}
}}
<!-- Store the mapped result into another array -->
{{#arraydefine: MAPPED_QUERY_RESULT
| {{#arraymap: {{#arrayprint: QUERY_RESULT}}
| ,
| $O <!-- NOTE: array map iterator value -->
| {{#explode: $O <!-- NOTE: explode by hash -->
| #
| 0
}}
}}
| ,
| unique
}}
<!-- Generate links markup -->
{{#arraymap: {{#arrayprint: MAPPED_QUERY_RESULT}}
| ,
| $O
| [[$O]] <!-- NOTE: plain links -->
}}
The notes from the code above:
NOTE: array item link - Not suppressing the links causes the mapper to be more complicated (including parsing HTML <span> tags and class attributes).
NOTE: limit - This is probably the biggest issue here as the number of subobjects affects the query result. SMW by default limits the query results, and the maximum query limit cannot be overridden as far as I know. Having more rows, which count is greater than the limits is, will cause the 'Further limits' link to appear. Actually speaking, I have no idea how to work around it nicely.
NOTE: array map iterator value - {{#arraymap}} seems to replace strings in the simplest way like sed or a simple text editor app do. So $O is used as the iterator value placeholder for the formula parameter trying not to clash with other string tokens.
NOTE: explode by hash - #ask subobject results generate hashed links like PageA#_159c1f213de2fcaf165f2c9c5c56686b. Just getting rid of them. In case you need to strip wiki links, you might also play around with [[ or | (encoded like [<nowiki/>[ and <nowiki>|</nowiki> respectively)
NOTE: plain links - The generated links will have underscores instead of spaces. Unfortunately, [[{{#replace: $O | _ | <nowiki> </nowiki>}}]] didn't work for me -- the underscores are simply consumed for some reason, however this approach is also recommended at the #replace function wiki page.
Some links:
SMW array result format
SMW configuration
SMW further results
#arraymap:
#explode:
#replace:
Help:List the set of unique values for a property (pay attention at the "Limitations and issues" section)
Many, many times, I have wanted to create a template that takes a list of values, and displays them in a table, each on their own line. I've tried hiding the comma in a span, but that breaks the table.
<span style="display:none;">{{#arraymap: {{{programmers|}}}|,|x|</span><!--
-->{{!}} Programmer: {{!!}} x
{{!-}}<span style="display:none;">}}</span>
Is there a method of hiding the delimiter and still getting a table, or perhaps, is there a separate way to do this altogether?
If you want a full simplified testcase, I have the following input:
{{authors|programmers=Ryan Scheel, Ryan Dean}}
and I want the following output:
{| class="wikitable"
|-
! colspan="2" style="text-align:center;" ! Authors
|-
| Programmer: || Ryan Scheel
|-
| Programmer: || Ryan Dean
|}
or in template form:
{{{!}} class="wikitable"
{{!-}}
! colspan="2" style="text-align:center;" ! Authors
{{!-}}
{{!}} Programmer: {{!!}} Ryan Scheel
{{!-}}
{{!}} Programmer: {{!!}} Ryan Dean
{{!}}}
I solved your problem by passing an empty 5th argument to the function[1]. This argument defines what to replace the delimiter with.
{{#arraymap: Ryan Scheel, Ryan Dean|,|x|<nowiki />
{{!-}}
{{!}} Programmer: {{!!}} x
|<!-- empty 5th parameter -->}}
expanded result will be as following:
{|
<nowiki />
|-
| Programmer: || Ryan Scheel<nowiki />
|-
| Programmer: || Ryan Dean
|}
I slightly modified your example for my own convenience during my tests, feel free to adjust it to your taste. I put the |- (HTML <tr>) before the | (HTML <td>) because it is more logical.
More important, as you may already know, arguments of parser functions are trimed[2]. The problem is that wiki tables markup ({|, |-, etc.) should be at the beginning of the lines of the source, otherwise it is not interpreted[3]. So, in order to insert a linebreak, in this example before the |-'s, I used the pretty <nowiki /> trick ;-)
As a side note, your line ! colspan="2" (...) ! Authors has a mistake, the ! before "Authors" has to be a | instead.
[1] documentation at http://www.mediawiki.org/wiki/Extension:Semantic_Forms/Semantic_Forms_and_templates
[2] contrary to unnamed parameters of templates!
[3] The only exception, as far as I know, is that you can put spaces and HTML comments before.
I have made no secret of my disdain for BBCode and support for more readable text-to-HTML converters like Markdown, which is what SO uses. "Canonical" Markdown however doesn't have a syntax to define tables. So, I am trying to come up with an extension that does just that.
Above all, it should be easy to read and write. Of course it also shouldn't be conflict with existing Markdown syntax. PHP Markdown has syntax for tables that looks like:
| First Header | Second Header |
| ------------- | ------------- |
| Content Cell | Content Cell |
| Content Cell | Content Cell |
For some reason, this strikes me as "not enough enough" (mainly because it looks a little too verbose). Does anyone know of a Markdown dialect with a nicer syntax? You are welcome to write your own as well.
Bonus points if it's not extraordinarily difficult to parse but still flexible enough to handle alignments (horizontal and vertical), table headers and possibly colspan and rowspan.
I like Textile's table syntax. It looks like:
|_. a header cell |_. another header |
|_. one more header |=. centered cell |
| regular cell |>. right-aligned cell |
The parser doesn't care about whitespace. This syntax is flexible and avoids the rigidity of syntaxes (like yours, Reddit's, etc.) requiring a "separator" line between a single header row and the rest of the table.