Template:Evenodd: Difference between revisions

Want an adless experience? Log in or Create an account.
no edit summary
(I guess caching parameterless templates is a smart thing to do... it just doesn't agree with global variables.)
No edit summary
Line 1: Line 1:
<onlyinclude>{{#if: {{#var:evenodd}}
<onlyinclude>{{#if: {{#var:evenodd}}
| {{#switch: {{#var:evenodd}}
| {{#switch: {{#var:evenodd}}
   | even = {{#vardefineecho:evenodd|odd}}
   | even = {{#vardefineecho:evenodd|{{{1|odd}}}}}
   | odd = {{#vardefineecho:evenodd|even}}
   | odd = {{#vardefineecho:evenodd|{{{1|even}}}}}
   }}
   }}
| {{#vardefineecho:evenodd|{{{init|odd}}}}}
| {{#vardefineecho:evenodd|{{{1|odd}}}}}
}}</onlyinclude>
}}</onlyinclude>


Line 13: Line 13:
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.
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}}