Skip to content

Instantly share code, notes, and snippets.

@bheyde
Last active December 22, 2015 09:39
Show Gist options
  • Save bheyde/6453757 to your computer and use it in GitHub Desktop.
Save bheyde/6453757 to your computer and use it in GitHub Desktop.
Requirements For Use
5.18 Engine or Higher
Available on any page, no item assignment required.
Definition
<mvt:assign name="variable" value="expression, string or number" />
Executes the expression contained within value and saves that value to the variable defined in the name attribute.
Attributes
name
This can be a local or global variable as defined by l. or g.
examples: l.myvariable or g.myglobalvariable.
If no prefix (l. or g.) is given it defaults to be a global variable.
value
The value can either be an expression a string, a number or a combination of all three.
expressions
Any value contained in the value attribute will automatically be treated as an expression. This means text will be treates as variables and any function available with the Miva Empresa engine (link) will be evaluated.
Example:
<mvt:assign name="l.myvariable" value="substring(l.myvariable, 2, len(l.myvariable) " /> //finds the substring of l.myvariable starting at the second character until the end of the string and saves that value back into l.myvariable
strings
Strings are alwsys defined by single quotes.
Example:
<mvt:assign name="l.myvariable" value=" 'This is an example of a string' " />
numbers
Numbers do not need to be enclosed by single quotes.
Example:
<mvt:assign name="l.myvariable" value="10" /> // Outputs 10
<mvt:assign name="l.myvariable" value="(10+10) * 5" /> // Outputs 100
Concatenation
The $ is the concatenation operator in the Miva Template Language.
Example:
<mvt:assign name="g.myvariable" value=" 'The length of this string is: ' $ len('hello world') " />
&mvt:global:myvariable; // Outputs: "The length of this string is: 11"
Outputing Values to the Page
If you want to display a value to the screen it needs to a global variable or part of the l.settings structure.
Example:
<mvt:assign name="g.myvariable" value="10" />
&mvt:global:myvariable; // prints 10
<mvt:assign name="l.settings:myvariable" value=" 'hello world' " />
&mvt:myvariable; // prints "hello world"
<mvt:assign name="l.myvariable" value=" 'this is a test' " />
&mvt:myvariable; // This will NOT print anything to the page since it is not part of the l.settings structure.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment