Template:Code/doc: Difference between revisions From Online Manual

Jump to: navigation, search
m (code tag)
(Three simple rules)
Line 1: Line 1:
This template is used to style code, in circumstances where the <nowiki><code></nowiki> tag does not do the job.
This template is used to style blocks of code. It adds a horizontal line above and below the code block.  
It adds a horizontal line above and below the code block.
It makes sure that the code block does not jump in and out of <nowiki><pre></nowiki> mode as you increase and decrease indentation.
 
To avoid the most common problems with this template, explicitly name the parameter, and do not start the parameter contents with "wiki-removable whitespace". Any occurance of <nowiki>|</nowiki> in the code must be replaced by &amp;#124; or {{tl|!}}
<pre>{{code
<pre>{{code
|1=&amp;nbsp;  &lt;td align="right" class="catbg"&gt;
|1=&amp;nbsp;  &lt;td align="right" class="catbg"&gt;
Line 13: Line 9:
     &lt;/td&gt;}}
     &lt;/td&gt;}}


For more information on the use of "=" and <nowiki>|</nowiki> within parameter values, please see [http://meta.wikimedia.org/wiki/Help:Template Meta:Help:Template]
The <nowiki><code></nowiki> tag should be used, instead, for inline code fragments, but will not do a good job with multi-line fragments in which some lines are indented and some are not.
 
Here are three simple rules to follow that will help you show your code the way you want it.
# If your code fragment begins with whitespace (space or tabs), stop the wiki-parser from "eating" those spaces
#*Enclose your code in &lt;nowiki&gt; tags
#*Start your code with a non-whitespace character (add a blank comment line, for example)
#*Start your code with a &amp;nbsp; character
#If your code contains <nowiki>|</nowiki>, use &amp;#124; or {{tl|!}} instead. Otherwise, the wiki parser will think everything after the {{|}} belongs to a different parameter of the wiki template. See [http://meta.wikimedia.org/wiki/Help:Template Meta:Help:Template] for more on this.
#Remember that the code must follow '''{{|}}1=''' if your code contains any equals signs. Even though the wikiparser permits leaving out the '''1=''', this will not work if the parameter value contains an '''='''. The parser would think everything to the left of the first '''=''' is the name of some other parameter, and you won't see your code displayed.

Revision as of 10:57, 18 April 2011

This template is used to style blocks of code. It adds a horizontal line above and below the code block.

{{code
|1=&nbsp;   <td align="right" class="catbg">
        <img src="', $settings['images_url'], '/smflogo.gif" style="margin: 2px;" alt="" />
    </td>}}
    <td align="right" class="catbg">
        <img src="', $settings['images_url'], '/smflogo.gif" style="margin: 2px;" alt="" />
    </td>

The <code> tag should be used, instead, for inline code fragments, but will not do a good job with multi-line fragments in which some lines are indented and some are not.

Here are three simple rules to follow that will help you show your code the way you want it.

  1. If your code fragment begins with whitespace (space or tabs), stop the wiki-parser from "eating" those spaces
    • Enclose your code in <nowiki> tags
    • Start your code with a non-whitespace character (add a blank comment line, for example)
    • Start your code with a &nbsp; character
  2. If your code contains |, use &#124; or {{!}} instead. Otherwise, the wiki parser will think everything after the {{|}} belongs to a different parameter of the wiki template. See Meta:Help:Template for more on this.
  3. Remember that the code must follow {{|}}1= if your code contains any equals signs. Even though the wikiparser permits leaving out the 1=, this will not work if the parameter value contains an =. The parser would think everything to the left of the first = is the name of some other parameter, and you won't see your code displayed.


Advertisement: