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

Jump to: navigation, search
(Three simple rules)
(tried to simplify and clarify the warnings.)
 
Line 12: Line 12:


Here are three simple rules to follow that will help you show your code the way you want it.
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
# If your code fragment begins with whitespace (space or tabs), stop the wiki-parser from "eating" those spaces in one of these ways
#*Enclose your code in <nowiki> tags
#*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 non-whitespace character (add a blank comment line, for example)
#*Start your code with a   character
#*Start your code with a   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.
# '''<nowiki>|</nowiki>''' in your code will confuse the wiki parser terribly. Use {{tl|!}} or &amp;#124; instead. See [http://meta.wikimedia.org/wiki/Help:Template Meta:Help:Template] for more on how the {{|}} is used within wiki templates.
#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.
# '''=''' in your code will confuse the wiki parser UNLESS you use <code>'''{{|}}1='''</code> before it. Otherwise, the parser thinks everything before the fires '''=''' is the name of some wiki template parameter, and you'll see no code displayed at all.  [http://meta.wikimedia.org/wiki/Help:Template Meta:Help:Template] for more on this.

Latest revision as of 15:12, 12 October 2012

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 in one of these ways
    • 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. | in your code will confuse the wiki parser terribly. Use {{!}} or &#124; instead. See Meta:Help:Template for more on how the {{|}} is used within wiki templates.
  3. = in your code will confuse the wiki parser UNLESS you use {{|}}1= before it. Otherwise, the parser thinks everything before the fires = is the name of some wiki template parameter, and you'll see no code displayed at all. Meta:Help:Template for more on this.


Advertisement: