Template:!/Doc: Difference between revisions

From Octave
Jump to navigation Jump to search
(documentation for the {{!}} template)
 
(use {{!}} for Code template)
 
(One intermediate revision by the same user not shown)
Line 19: Line 19:
* {{Codeline|if (nargin > 2 {{!}}{{!}} nargin < 5), print_usage; endif}}
* {{Codeline|if (nargin > 2 {{!}}{{!}} nargin < 5), print_usage; endif}}


== Comparison with {{pipe}} ==
== Comparison with {{Codeline|<nowiki>{{pipe}}</nowiki>}} ==


{{Codeline|<nowiki>{{pipe}}</nowiki>}} is not a duplicate of {{Codeline|<nowiki>{{!}}</nowiki>}}. These are two different templates with very different functionality. {{Codeline|<nowiki>{{pipe}}</nowiki>}} inserts the code {{Codeline|&amp;#124;}}, which does render as a pipe in the web browsers. But it does not interfere with the MediaWiki parser. Thus it can be used in text inside wikitables and parserfunctions without causing any altered function of them. {{Codeline|<nowiki>{{!}}</nowiki>}} inserts an actual pipe character that is parsed by the MediaWiki parser. Thus it does have effect inside wikitables.
{{Codeline|<nowiki>{{pipe}}</nowiki>}} is not a duplicate of {{Codeline|<nowiki>{{!}}</nowiki>}}. These are two different templates with very different functionality. {{Codeline|<nowiki>{{pipe}}</nowiki>}} inserts the code {{Codeline|&amp;#124;}}, which does render as a pipe in the web browsers. But it does not interfere with the MediaWiki parser. Thus it can be used in text inside wikitables and parserfunctions without causing any altered function of them. {{Codeline|<nowiki>{{!}}</nowiki>}} inserts an actual pipe character that is parsed by the MediaWiki parser. Thus it does have effect inside wikitables.


Basically, {{Codeline|<nowiki>{{!}}</nowiki>}} is used to delay parsing by the pipe for ''one'' round so that a wikitable pipe can be placed inside and controlled by for instance an #if statement.
Basically, {{Codeline|<nowiki>{{!}}</nowiki>}} is used to delay parsing by the pipe for ''one'' round so that a wikitable pipe can be placed inside and controlled by for instance an #if statement. If you are using the {{Codeline|Code}} template, you will want to use {{Codeline|<nowiki>{{!}}</nowiki>}}.

Latest revision as of 13:43, 28 June 2012

This is an auxiliary template allowing the encoding of | within template parameters, because the pipe character is normally interpreted as a separator. This template is necessary if the character is used in wiki table syntax, or if the parameter is automatically wikilinked and you wish to use a pipe to specify different link text from the target page name. In other cases it is better to use the {{pipe}} template.

This template cannot be used for putting the character as text in a wiki table; in that case, again, {{pipe}} can be used. See below for comparison between the two templates.

Note that no special template is needed for "!" (exclamation mark).

A simple example[edit]

The following template code for Template:Codeline using an ordinary pipe character,

  • {{Codeline|if (nargin > 2 || nargin < 5), print_usage; endif}}

produces:

  • if (nargin > 2

whereas this code using the {{!}} meta-template,

  • {{Codeline|if (nargin > 2 {{!}}{{!}} nargin < 5), print_usage; endif}}

produces:

  • if (nargin > 2 || nargin < 5), print_usage; endif

Comparison with {{pipe}}[edit]

{{pipe}} is not a duplicate of {{!}}. These are two different templates with very different functionality. {{pipe}} inserts the code &#124;, which does render as a pipe in the web browsers. But it does not interfere with the MediaWiki parser. Thus it can be used in text inside wikitables and parserfunctions without causing any altered function of them. {{!}} inserts an actual pipe character that is parsed by the MediaWiki parser. Thus it does have effect inside wikitables.

Basically, {{!}} is used to delay parsing by the pipe for one round so that a wikitable pipe can be placed inside and controlled by for instance an #if statement. If you are using the Code template, you will want to use {{!}}.