Help:Cargo template: Difference between revisions

Jump to navigation Jump to search
Line 298: Line 298:
These tags control what happens when a template is transcluded (used with <code>{{TemplateName}}</code>):
These tags control what happens when a template is transcluded (used with <code>{{TemplateName}}</code>):


* '''<noinclude>''': Content inside these tags appears ONLY on the template page, not on pages using the template. Use for:
* '''<nowiki><noinclude></nowiki>''': Content inside these tags appears ONLY on the template page, not on pages using the template. Use for:
** <code>#cargo_declare</code> (runs once).
** <code>#cargo_declare</code> (runs once).
** Documentation (see below).
** Documentation (see below).
** Categories for the template page, like <code>[[Category:Templates]]</code>.
** Categories for the template page, like <code><nowiki>[[Category:Templates]]</nowiki></code>.
** Example: <code>&lt;noinclude&gt;[[Category:Cargo templates]]&lt;/noinclude&gt;</code>.
** Example: <code>&lt;noinclude&gt;<nowiki>[[Category:Cargo templates]]</nowiki>&lt;/noinclude&gt;</code>.
* '''<includeonly>''': Content appears ONLY when the template is transcluded, not on the template page. Use for:
* '''<nowiki><includeonly></nowiki>''': Content appears ONLY when the template is transcluded, not on the template page. Use for:
** <code>#cargo_store</code> (runs per use).
** <code>#cargo_store</code> (runs per use).
** <code>#cargo_attach</code> (in two-template setups).
** <code>#cargo_attach</code> (in two-template setups).
Line 314: Line 314:
* Always preview transclusions to check for errors.
* Always preview transclusions to check for errors.


== Documentation: Inline vs. {{Doc}} Subpage ==
== Documentation: Inline vs. <nowiki>{{Doc}}</nowiki> Subpage ==


Documentation helps editors understand how to use the template. You can place it directly on the template page (inline) within <code>&lt;noinclude&gt;</code> tags or in a separate subpage, typically named <code>Template:TemplateName/doc</code>, using the <code>{{Doc}}</code> template. We recommend using a <code>{{Doc}}</code> subpage for most Cargo templates due to its advantages.
Documentation helps editors understand how to use the template. You can place it directly on the template page (inline) within <code>&lt;noinclude&gt;</code> tags or in a separate subpage, typically named <code>Template:TemplateName/doc</code>, using the <code>{{Doc}}</code> template. We recommend using a <code><nowiki>{{Doc}}</nowiki></code> subpage for most Cargo templates due to its advantages.


=== Inline Documentation ===
=== Inline Documentation ===
Line 323: Line 323:
==== Example: Inline Documentation ===
==== Example: Inline Documentation ===
<pre>
<pre>
<noinclude>
<nowiki><noinclude></nowiki>
== Documentation for Template:Book ==
== Documentation for Template:Book ==
This template stores book info in Cargo for querying.
This template stores book info in Cargo for querying.
Line 341: Line 341:
</pre>
</pre>


=== {{Doc}} Subpage Documentation ===
=== <nowiki>{{Doc}}</nowiki> Subpage Documentation ===
Using a subpage like <code>Template:Book/doc</code> involves creating a separate page with the documentation and including it on the template page with <code>{{Doc}}</code>.
Using a subpage like <code>Template:Book/doc</code> involves creating a separate page with the documentation and including it on the template page with <code><nowiki>{{Doc}}</nowiki></code>.


==== Example: Template:Book/doc ====
==== Example: Template:Book/doc ====
Line 368: Line 368:


<pre>
<pre>
<noinclude>
<nowiki><noinclude></nowiki>
{{Doc}}
{{Doc}}
[[Category:Cargo templates]]
[[Category:Cargo templates]]
Line 378: Line 378:
! Aspect
! Aspect
! Inline Documentation
! Inline Documentation
! {{Doc}} Subpage
! <nowiki>{{Doc}}</nowiki> Subpage
|-
|-
| '''Location'''
| '''Location'''
| On the template page in <code>&lt;noinclude&gt;</code>.
| On the template page in <code>&lt;noinclude&gt;</code>.
| On a separate subpage, included with <code>{{Doc}}</code>.
| On a separate subpage, included with <code><nowiki>{{Doc}}</nowiki></code>.
|-
|-
| '''Ease of Setup'''
| '''Ease of Setup'''
Line 414: Line 414:


=== Recommendation ===
=== Recommendation ===
Use a <code>{{Doc}}</code> subpage for Cargo templates, especially on larger wikis or for templates with complex logic or extensive documentation. This keeps the template page focused on code, makes documentation easier to maintain, and aligns with MediaWiki best practices. For very simple templates with minimal documentation, inline placement in <code>&lt;noinclude&gt;</code> may be sufficient, but subpages scale better for most use cases.
Use a <code><nowiki>{{Doc}}</nowiki></code> subpage for Cargo templates, especially on larger wikis or for templates with complex logic or extensive documentation. This keeps the template page focused on code, makes documentation easier to maintain, and aligns with MediaWiki best practices. For very simple templates with minimal documentation, inline placement in <code>&lt;noinclude&gt;</code> may be sufficient, but subpages scale better for most use cases.


== Full Template Examples ==
== Full Template Examples ==
Line 422: Line 422:
=== Example 1: Template:Book ===
=== Example 1: Template:Book ===
<pre>
<pre>
<noinclude>
<nowiki><noinclude></nowiki>
This is the "Book" template.
This is the "Book" template.


Line 434: Line 434:
[[Category:Cargo templates]]
[[Category:Cargo templates]]
</noinclude>
</noinclude>
<includeonly>
<nowiki><includeonly></nowiki>
{{#cargo_store:_table=Books}}
{{#cargo_store:_table=Books}}
{|
{|
Line 454: Line 454:
=== Example 2: Template:Author ===
=== Example 2: Template:Author ===
<pre>
<pre>
<noinclude>
<nowiki><noinclude></nowiki>
This is the "Author" template.
This is the "Author" template.


Line 463: Line 463:
[[Category:Cargo templates]]
[[Category:Cargo templates]]
</noinclude>
</noinclude>
<includeonly>
<nowiki><includeonly></nowiki>
{{#cargo_store:_table=Authors}}
{{#cargo_store:_table=Authors}}
{|
{|

Navigation menu