Template:Evenodd: Difference between revisions

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


==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 to the named parameter "init": {{Usage|init{{=}}even}}