<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.runerealm.org/index.php?action=history&amp;feed=atom&amp;title=Template%3AVar%2Fdoc</id>
	<title>Template:Var/doc - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.runerealm.org/index.php?action=history&amp;feed=atom&amp;title=Template%3AVar%2Fdoc"/>
	<link rel="alternate" type="text/html" href="https://wiki.runerealm.org/index.php?title=Template:Var/doc&amp;action=history"/>
	<updated>2026-06-15T16:30:22Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.1</generator>
	<entry>
		<id>https://wiki.runerealm.org/index.php?title=Template:Var/doc&amp;diff=38786&amp;oldid=prev</id>
		<title>Alex: Created page with &quot;{{documentation}}  The &#039;&#039;&#039;Var&#039;&#039;&#039; template is used to store data in the cache for later use.  ==Usage== &lt;pre&gt;{{Var|name|data}}&lt;/pre&gt;  ===Name=== The name of the variable. Case sensitive.  ===Data=== The data to be stored in the variable. The literal value is stored and is not evaluated (unless you also store the appropriate functions) - if you store 6*7, when you recall it you will get the result &lt;code&gt;6*7&lt;/code&gt;, not 42; if you store &lt;code&gt;&lt;nowiki&gt;{{#expr:6*7}}&lt;/nowiki&gt;&lt;...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.runerealm.org/index.php?title=Template:Var/doc&amp;diff=38786&amp;oldid=prev"/>
		<updated>2024-10-17T11:06:49Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{documentation}}  The &amp;#039;&amp;#039;&amp;#039;Var&amp;#039;&amp;#039;&amp;#039; template is used to store data in the cache for later use.  ==Usage== &amp;lt;pre&amp;gt;{{Var|name|data}}&amp;lt;/pre&amp;gt;  ===Name=== The name of the variable. Case sensitive.  ===Data=== The data to be stored in the variable. The literal value is stored and is not evaluated (unless you also store the appropriate functions) - if you store 6*7, when you recall it you will get the result &amp;lt;code&amp;gt;6*7&amp;lt;/code&amp;gt;, not 42; if you store &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#expr:6*7}}&amp;lt;/nowiki&amp;gt;&amp;lt;...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{documentation}}&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;Var&amp;#039;&amp;#039;&amp;#039; template is used to store data in the cache for later use.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
&amp;lt;pre&amp;gt;{{Var|name|data}}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Name===&lt;br /&gt;
The name of the variable. Case sensitive.&lt;br /&gt;
&lt;br /&gt;
===Data===&lt;br /&gt;
The data to be stored in the variable. The literal value is stored and is not evaluated (unless you also store the appropriate functions) - if you store 6*7, when you recall it you will get the result &amp;lt;code&amp;gt;6*7&amp;lt;/code&amp;gt;, not 42; if you store &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#expr:6*7}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; you &amp;#039;&amp;#039;will&amp;#039;&amp;#039; get the result &amp;lt;code&amp;gt;42&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Recalling data==&lt;br /&gt;
Recalling data is done by use of the #var parser function:&lt;br /&gt;
&amp;lt;pre&amp;gt;{{#var:name}}&amp;lt;/pre&amp;gt;&lt;br /&gt;
where &amp;#039;&amp;#039;name&amp;#039;&amp;#039; is the same named used in the var template above.&lt;br /&gt;
&lt;br /&gt;
==Expansion on usage==&lt;br /&gt;
Variables can be redefined where needed - you can use the Var template many times.&lt;br /&gt;
&lt;br /&gt;
Variables can be called where needed - you can use the #var parser function many times.&lt;br /&gt;
&lt;br /&gt;
Variables can be defined recursively, that is defined as a function as themselves. For example:&lt;br /&gt;
&amp;lt;pre&amp;gt;{{Var|i|0}}&lt;br /&gt;
&lt;br /&gt;
{{Var|i|{{#expr:{{#var:i}}+1}}}}&amp;lt;/pre&amp;gt;&lt;br /&gt;
The first line initialises the variable i to 0 (required to prevent expression errors), and the second will increment i by one each time it is used. If you place the second line into a template that is used multiple times on a page e.g. a table row template, you can recall i to find something that may be of importance in context e.g. the number of rows in the template. As an additional note, the increment doesn&amp;#039;t have to be 1, it can be any number - it doesn&amp;#039;t even have to be a fixed number, it can be a function of some other parameters in the template.&lt;br /&gt;
&lt;br /&gt;
==Rationale==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;quot;But I know how to use the #vardefine parser function. Isn&amp;#039;t this the exact same thing?&amp;quot;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Yes, it is. The Var templates uses the #vardefine parser function to define the variables. So what&amp;#039;s the point of this template?&lt;br /&gt;
&lt;br /&gt;
A problem with the design of the variables extension is that vardefine is always executed even if it is on the false path of a conditional parser function: for example, if you created a construct such as&lt;br /&gt;
&amp;lt;pre&amp;gt;{{#ifexpr: ...&lt;br /&gt;
    |{{#vardefine:a|b}}&lt;br /&gt;
    |{{#vardefine:a|c}}&lt;br /&gt;
}}&amp;lt;/pre&amp;gt;&lt;br /&gt;
Variable a will now always hold c, regardless of whether the expression is true or false.&lt;br /&gt;
&lt;br /&gt;
There are two ways around this. The first is to move the #vardefine to the outside of the conditional parser: following the previous example, the required construct would be similar to&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;{{#vardefine:a|{{#ifexpr: ... |b|c}}}}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, sometimes you can&amp;#039;t move the #vardefine outside, it logically makes more sense or is easier to follow to leave the #vardefine on the inside. This is where the Var template comes in. As the template is not expanded if it is on the false path, the #vardefine is not present and cannot define variables where it shouldn&amp;#039;t. Thus a construct like this will also work for the above example:&lt;br /&gt;
&amp;lt;pre&amp;gt;{{#ifexpr: ...&lt;br /&gt;
    |{{Var|a|b}}&lt;br /&gt;
    |{{Var|a|c}}&lt;br /&gt;
}}&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
[[mw:Extension:VariablesExtension|The Variables Extension page on MediaWiki]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;includeonly&amp;gt;[[Category:Transclusion templates|{{PAGENAME}}]]&amp;lt;/includeonly&amp;gt;&lt;/div&gt;</summary>
		<author><name>Alex</name></author>
	</entry>
</feed>