Help:Templates: Difference between revisions

Jump to navigation Jump to search
m
(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?)
m (→‎To include or not include: Some last fixes)
Line 106: Line 106:
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.
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'':
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 that both the <tt><nowiki><includeonly></nowiki></tt> and <tt><nowiki><noinclude></nowiki></tt> tags are right behind the text of the template, as a having a line break 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>
  <nowiki>Hello, {{{1|}}}{{{2|stranger}}}!<includeonly>[[Category:Pages that says hello]]</includeonly><noinclude>
Line 117: Line 117:


== Usage ==
== 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;
  &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;


;parameter:  Optional title, for example "<tt>Dr.</tt>"
;parameter:  Optional title, for example "<tt>Dr.</tt>"

Navigation menu