Learn Miva


Structures

[Video Tutorial](http://www.miva.com/videos/web_developers/structures) Structures are a lot like arrays.
Created: 1427238160
View "Structures"
<mvt:assign name="l.settings:example:foo" value="'bar'" /> <mvt:assign name="l.settings:example:bar" value="'baz'" /> &mvt:example:foo;<br> &mvt:example:bar;<br> <hr> <mvt:assign name="l.settings:example:list[0]" value="'Bananas'" /> <mvt:assign name="l.settings:example:list[1]" value="'Milk'" /> <mvt:assign name="l.settings:example:list[2]" value="'Bread'" /> <mvt:assign name="l.settings:example:list[3]" value="'Cereal'" /> &mvt:example:list[0];<br> &mvt:example:list[1];<br> &mvt:example:list[2];<br> &mvt:example:list[3];<br> <br> <mvt:foreach iterator="item" array="example:list"> &mvt:item;<br> </mvt:foreach> <hr> <mvt:assign name="l.settings:example:states[0]:abbr" value="'CA'" /> <mvt:assign name="l.settings:example:states[0]:name" value="'California'" /> <mvt:assign name="l.settings:example:states[1]:abbr" value="'FL'" /> <mvt:assign name="l.settings:example:states[1]:name" value="'Florida'" /> &mvt:example:states[0]:abbr; - &mvt:example:states[0]:name;<br> &mvt:example:states[1]:abbr; - &mvt:example:states[1]:name;<br> <br> <mvt:foreach iterator="state" array="example:states"> &mvt:state:abbr; - &mvt:state:name;<br> </mvt:foreach> <hr> <h4>Print Example Structure:</h4> <mvt:eval expr="decodeattribute(glosub(miva_array_serialize(l.settings:example), ',', '<br>'))" />
 

Output Encoding

[Documentation](http://www.miva.com/template-language/miva_template_language/entities_&_encoding.html) [Video Tutorial](http://www.miva.com/videos/web_developers/output-encoding)
Created: 1427238108
View "Output Encoding"
<mvt:assign name="l.settings:sample" value="'<i>Hello World.</i>'" /> <h2>No Encoding</h2> &mvt:sample; <h2>Entity Encoding </h2> <p><small>Can help prevent cross side scripiting</small></p> &mvte:sample; <h2>Attribute Encoding </h2> <p><small>Great for URLs</small></p> &mvta:sample; <h2>JavaScript Encoding</h2> &mvtj:sample; <h2>Sluggified Encoding</h2> &mvts:sample; <mvt:comment> <!-- Click the Result's "View Source" Button for more details. --> </mvt:comment>
 

Entities

[Documentation](http://www.miva.com/template-language/miva_template_language/entities_&_encoding.html) [Tutorial](http://www.miva.com/videos/web_developers/entities)
Created: 1427238072
View "Entities"
<h3>Entity</h3> <p>Outputs variables to the page.</p> Example: &mvt:store:name; <h3>Variable</h3> <p>Is used to store and retreive information. Also, allows you to program logic</p> Example: l.settings:store:name <h3>This condition will not work</h3> <mvt:comment> <mvt:if expr="&mvt:store:name; EQ 'test' "> This does not work. Compile Error </mvt:if> </mvt:comment> <h3>This condition will work</h3> <mvt:if expr="l.settings:store:name EQ 'MVT Fiddle' "> <p>This does work!</p> </mvt:if> <h3>This will output to the page</h3> <p>Welcome to &mvt:store:name;!</p> <h3>This will not output to the page</h3> </p>Welcome to l.settings:store:name;</p>
 

Global vs Local Variables

Each Miva Merchant Entity has a scope. It is either a local variable which is accessed using `l.settings:` or a global variable accessed using `g.` [Documentation](http://www.miva.com/template-language/miva_template_language/global_&_local_variables.html) [Tutorial](http://www.miva.com/videos/web_developers/entities)
Created: 1427238028
View "Global vs Local Variables"
<h2>Global Variables</h2> <mvt:assign name="g.foo" value=" 'bar' " /> g.foo is, "&mvt:global:foo;"<br/> <mvt:if expr="g.foo EQ 'bar'"> g.foo EQ 'bar' is true!<br/> </mvt:if> <h2>Local Variables</h2> <h4>With l.settings</h4> <mvt:assign name="l.settings:foo" value=" 'bar' " /> l.settings:foo is, "&mvt:foo;"<br/> <mvt:if expr="l.settings:foo EQ 'bar'"> l.settings:foo EQ 'bar' is true!<br/> </mvt:if> <h4>Without l.settings</h4> <mvt:assign name="l.foo" value=" 'bar' " /> l.foo is, "&mvt:foo;"<br/> <mvt:if expr="l.foo EQ 'bar'"> l.foo EQ 'bar' is true!<br/> </mvt:if>
 

mvt:eval

Executes the expression contained within expr attribute and outputs the expression's value directly to the page. It opperates just like mvt:assign exept that instead of saving the value/expression to a variable, it will output it directly to the page. [Documentation](http://www.miva.com/template-language/miva_template_language/mvteval.html)
Created: 1427237995
View "mvt:eval"
<mvt:eval expr="1 + 2" />
 

mvt:assign

Executes the expression contained within value and saves that value to the variable defined in the name attribute. [Documentation](http://www.miva.com/template-language/miva_template_language/mvtassign,_mvteval.html)
Created: 1427237965
View "mvt:assign"
<mvt:assign name="g.sum" value="1 + 2" /> The sum is: &mvt:global:sum;