views:

55

answers:

2

I want to create a MediaWiki template which shows different text depending on where it is on a page.

Specifically, it is before the first heading it should show text like, "this template is applicable to this whole page"

Alternatively, if it is within a section on a page (after a heading) it should show text like, "this template is specifically applicable to this section".

I know there are templates that make use of "If" (like If pagename); is there any way of detecting the template's location on the page?

+1  A: 

I don't think so. Your best bet would be to make multiple templates. That being said I'm sure you could write an extension that would do this.

Another way would be to add a variable in your template, that you change depending on which section it is in.

Adrian Archer
@Adrian - you mean, you're sure *someone* could - not me! =:-) Yeah, multiple templates is, of course, a pain because you'll either need to make changes in multiple templates or use a combination of templates. I checked Wikipedia - they *appear* to use the multiple templates approach. But I'm amazed - this should be a common problem.
Mark Robinson
PS @Adrian - you might be interested in this: http://area51.stackexchange.com/proposals/13716/wikispeedia
Mark Robinson
+1  A: 

With a lot of help from a colleague the answer is below. Put this into a template (which you then call from all your other templates containing header / instruction / etc. text).

<includeonly><css>
div.headingText { color: blue; border: 2px solid blue; background: lightcyan; width: 461px; padding:0.5em 0.5em 0.5em 0.5em; display: none; margin-bottom:-6px; }

h2 + div.headingText, h3 + div.headingText, h4 + div.headingText, h5 + div.headingText, h6 + div.headingText { display:block; margin-top:5px; }
</css>
<div class="headingText">'''{{{1|This [[tag]] applies only to this section.}}}'''</div></includeonly><noinclude>
your explanatory text
</noinclude>

Notes:

  1. This requires use of the CSS extension.
  2. What this actually does is show certain text if the tag is included directly below a title and no text otherwise. (It has default text in parameter 1 in this example, which can be changed.)
Mark Robinson