Help:Templates: Difference between revisions

Jump to navigation Jump to search
include and noinclude tags + example. The example broke the page in so many ways before I figured out how to fix it. Can you say un-*pre*-dictable?
(Where one can find template documentation, what happens without default values, other small fixes)
(include and noinclude tags + example. The example broke the page in so many ways before I figured out how to fix it. Can you say un-*pre*-dictable?)
Line 102: Line 102:
  <pre>{{hello |title=Dr. |name=Falken}}</pre>
  <pre>{{hello |title=Dr. |name=Falken}}</pre>
Hello, Dr. Falken!
Hello, Dr. Falken!
=== To include or not include ===
Sometimes you have content in a template that you do not want to be transcluded or that you want to have transcluded but not included in the template.  Consider for example the template documentation, of course you would not want it to be on every page the template is used on, also, sometimes you want a template to add a category to the page it is used on, but not to the template itself. This can be done using the <tt><nowiki><noinclude></nowiki></tt> and <tt><nowiki><includeonly></nowiki></tt> tags.
To go back to the ''Template:Hello'' template, the below example shows how ''Category:Pages that says hello'' is added to the page that uses the template but not to the template and how the documentation and ''Category:Hello templates'' is added to the template, but not the page it will be used on.  Note also that there both <tt><nowiki><includeonly></nowiki></tt> and <tt><nowiki><noinclude></nowiki></tt> starts right behind the text of the template, as a having a line break there would cause a line break when the template is used.  Here is the full ''Template:Hello'':
<nowiki>Hello, {{{1|}}}{{{2|stranger}}}!<includeonly>[[Category:Pages that says hello]]</includeonly><noinclude>
{{Informative template|1=
__NOTOC__
== Goal ==
This template can be used to show a friendly hello.
Adding this template to a page will automatically add that page to [[:Category:Pages that says hello]].
== Usage ==
&lt;nowiki&gt;{{&lt;/nowiki&gt;'''hello'''&lt;nowiki&gt;|&lt;/nowiki&gt;''title''&lt;nowiki&gt;|&lt;/nowiki&gt;''name''&lt;nowiki&gt;}}&lt;/nowiki&gt;&lt;nowiki&gt;
;parameter:  Optional title, for example "<tt>Dr.</tt>"
;parameter:  Optional name, defaults to "<tt>stranger</tt>"
== Examples ==
<pre>{{hello|Dr.|Falken}}</pre>
Hello, Dr. Falken!
<pre>{{hello}}</pre>
Hello, stranger!
}}
[[Category:Hello templates]]
</noinclude></nowiki>


== Translating templates ==
== Translating templates ==

Navigation menu