Help:Section/Editing sections of included templates
Editing sections of included templates
[edit]- For further information, see Transclusion
You can edit sections within included pages or templates. Clicking the edit link for a section takes you to the edit page of the separate page. This is also known as Transclusion.
The size of the section within the included page or template is determined by the headings in the main page where it is included. When a page is transcluded, all the text on the source page will be transcluded/included in the target page. This includes text placed before the first section heading on the source page. Consequently, if the edit link on the first section header of the transcluded text is clicked on the source page, section editing will open and the text before the first section header and the text of the next section will not be shown in the editor. In order to edit the entire source page's text, the editor must exit the editor when taken to the source page, and then click the edit link at the top of the source page. Similarly, if there are texts after the template tag without a heading, you need to click the headings before the template to edit it. This section shows how it works. To ensure clarity and consistency in rendered source pages that are transcluded to another page, follow these guidelines:
- Template structure – Avoid placing any text before the first section heading within a template.
- Handling sections – After using a template with sections, start a new section on the source page. This prevents conflicts between template sections and source page sections.
Additionally, consider the following practices for managing templates effectively:
- Template heading - Sometimes it's helpful to start a template with a heading, even if it's just one section. This makes editing easier.
- Parameter use - When editing templates, remember parameters, such as
{{{1}}}, are changed in the target page, not directly in the template. Although this may not be immediately apparent in the rendered page, providing explanatory text or an additional edit link can enhance user understanding. __NOEDITSECTION__behavior switch – The__NOEDITSECTION__behavior switch affects the template and any pages it's added to, along with other templates on the same page. Instead, consider replacing MediaWiki section header markup with HTML header markup within the template, causing the headers to remain visually consistent while avoiding recognition as editable sections. This approach eliminates the need for__NOEDITSECTION__within the template.
For example, think of a template structured as follows:
== Template heading 1 ==
Content
=== Template heading 2 ===
Content
To prevent "edit section" links from appearing when transcluding a template, add __NOEDITSECTION__ within the template's code. However, this suppresses all "edit section" links on pages where the template is used.
Alternatively, structuring the template with HTML heading tags (<h2>, <h3>, etc.) achieves the same visual effect without affecting other sections' edit links on transcluding pages.
<h2>Template heading 1</h2>
Content
<h3>Template heading 2</h3>
Content