views:

45

answers:

2

Using the variables extension, I want to change the background color of a cell in a table. So far I've done this:

{{#vardefine:green|<span style="background:Green; color:White">text</span>}}

The problem is that, when I add {{#var:green}} to the cell, only the text itself has a green background. Ideally, I want the whole cell to have a background color, like it does if I use this:

| bgcolor="#ff00ff" | test

or this

| style="background:silver" |silver

in the cell.

Does anyone know how to solve this?

A: 

That's simply not going to work. I presume your table row looks like this:

 | Not in span {{#var:green|Text}}

That means you're defining a span within the cell, not defining the color of the cell itself.

 | Not in span <span style="background:Green; color:White">Text</span>

Cell styles have to go before the content:

 | bgcolor="green" | Now it's all green

Instead, why not tag the row with a CSS class called 'green' and then define that in your Wiki CSS? See Help:Table#Style classes.

jpatokal
I assume you mean in "MediaWiki:Common.css" I'd rather not because that is a global page that affects every user. My assumption is that it will (if I add enough of these things) slow down wiki response. Is that correct?
Mark Robinson
Quite the contrary, CSS styling is probably much faster than custom variable processing and the overhead of an additional span in every cell.
jpatokal
Thanks for that, jpatokal!
Mark Robinson
+1  A: 

The answer was provided on the mwusers forum.

Essentially I need to:

  1. Create Template:! - which contains only | (see it on Wikipedia)

  2. Define the variables, e.g.:

    {{#vardefine: sample1 | bgcolor=green{{!}}Test}}

  3. Enter this in a cell:

    {{#var:sample1}}

Mark Robinson
Mark Robinson