Template:Evenodd: Difference between revisions

From Zelda Dungeon Wiki
Jump to navigation Jump to search
Want an adless experience? Log in or Create an account.
(Created page with "<onlyinclude>{{#if: {{#var:evenodd}} | {{#switch: {{#var:evenodd}} | even = {{#vardefineecho:evenodd|odd}} | odd = {{#vardefineecho:evenodd|even}} }} | {{#vardefineecho:...")
 
(fixed override feature, hopefully)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
<onlyinclude>{{#if: {{#var:evenodd}}
<onlyinclude>{{#switch: {{{1|}}}
| even = {{#vardefineecho:evenodd|even}}
| odd  = {{#vardefineecho:evenodd|odd}}
| {{#switch: {{#var:evenodd}}
| {{#switch: {{#var:evenodd}}
  | even = {{#vardefineecho:evenodd|odd}}
   | odd = {{#vardefineecho:evenodd|even}}
   | odd = {{#vardefineecho:evenodd|even}}
  | {{#vardefineecho:evenodd|odd}}<!--includes case "even"-->
   }}
   }}
| {{#vardefineecho:evenodd|{{{init|odd}}}}}
}}</onlyinclude>
}}</onlyinclude>


Line 11: Line 12:


==Usage==
==Usage==
Simply call this template with {{Usage}} each time the return value should be the opposite of what it was the last time it was called.
This template requires a small workaround to avoid the MediaWiki parser caching the template and not persisting the variable properly. It must be called with an empty argument (or any sort of argument), like so: <code><nowiki>{{Evenodd|}}</nowiki></code> - note the pipe. This is placed wherever an "odd" or "even" value is needed that's the opposite of the previous instance of this template on the same page.


When first called, it returns "odd", unless "even" is passed to the named parameter "init": {{Usage|init{{=}}even}}
When first called, it returns "odd", unless "even" is passed as an argument: {{Usage|even}}. Pass in "even" or "odd" in any instance to override the current value of the variable and start over from that point.




{{Cat|Utility Templates}}
{{Cat|Utility Templates}}

Latest revision as of 04:30, August 28, 2012

odd

Purpose

Each time this template is used within a given page, it toggles the variable "evenodd" between "even" and "odd", returning the resulting value. This can be used to dynamically switch between two different displays, such as rows in a list.

Usage

This template requires a small workaround to avoid the MediaWiki parser caching the template and not persisting the variable properly. It must be called with an empty argument (or any sort of argument), like so: {{Evenodd|}} - note the pipe. This is placed wherever an "odd" or "even" value is needed that's the opposite of the previous instance of this template on the same page.

When first called, it returns "odd", unless "even" is passed as an argument: {{Evenodd| even }}. Pass in "even" or "odd" in any instance to override the current value of the variable and start over from that point.