Help:Editing sections of included templates

From Meta, a Wikimedia project coordination wiki

Editing sections of included templates

This section appears in Help:Section.

The section editing feature can also be applied to a section of an included page or template. When clicking the edit link of the section that is transcluded, the link target will be the edit page of the separate page. This section, Help:Editing sections of included templates, is an example.

For the purpose of section editing the extent of a section is governed by the headings in the calling page itself. If there is a text before the first section heading of the separate page, this will appear as a part of the section of the parent page that includes the template tag, but clicking its section edit link will not show the wikitext of the separate page. Or if there is a text after the template tag without a specific section heading, to edit this text with section edit feature, one has to click the section headings preceding the template tag.

Therefore it tends to be confusing if the extent of sections in the rendered parent page is different from what the actual wikitext contains. To avoid this:

  • if a template has headings, do not put any text before the first heading
  • in the calling page, start a new section after a template that itself has sections

It may be convenient, where suitable, to start a template with a section heading, even if normally the contents of the template would not need a division into sections, and thus the template is only one section. The section editing feature can then be used for editing the template from a page that includes it, without specially putting an edit link. This template is an example, it does not need a division into sections, but has a heading at the top.

Note that a parameter value appearing in a template, for example "{{{1}}}", is not edited by editing the template but by editing the template tag in the calling page, even though the rendered page and its edit links do not automatically show that. Some explanatory text and/or an extra edit link can be useful.

The __NOEDITSECTION__ tag in any template affects both that template, the pages it's included on, and any other templates included on the same page. A workaround for this issue is described in phab:T48940: it is possible avoid the need to use __NOEDITSECTION__ in a template by to forcing the template to not recognize section headers as editable. Replacing mediawiki section header markup (surrounding headers with == markers to the desired depth) in the template with HTML header markup (surrounding headers with <h1></h1> tags, changing "1" to the desired depth) will result in headers visually identical to the first style, both on the template page and when transcluded, but which are not treated as editable sections.

For example, imagine a template called MyTemplate, containing the following:

==Template heading 1==
===Template heading 2===

Transcluding MyTemplate into another page will result in "edit section" links appearing after Template heading 1 and Template heading 2 on the page the template is transcluded into, which is often undesirable. Adding __NOEDITSECTION__ anywhere within the code of MyTemplate will result in suppression of these "edit section" links within the template, but also everywhere on pages it is transcluded into. If, however, MyTemplate contains the following rather than the above:

<h2>Template heading 1</h2>
<h3>Template heading 2</h3>

then the headings will be visually identical to the previous output of MyTemplate, except that they will not be accompanied by "edit section" links. Section headings elsewhere on pages where MyTemplate is transcluded will be unaffected, and abide by whatever the page's "edit section" settings are.