Browse All Fiddles


Basket #52331

Created: 1501002842
View "Basket #52331"
<mvt:assign name="l.settings:list[1]" value="'apples'" /> <mvt:assign name="l.settings:list[2]" value="'bananas'" /> <mvt:assign name="l.settings:list[3]" value="'carrots'" /> <h2>Before</h2> <mvt:foreach iterator="item" array="list"> &mvt:item;<br> </mvt:foreach> <mvt:do file="g.module_library_utilities" name="l.null" value="QuickSortArray(l.settings:list, '', 0)" /> <h2>After</h2> <mvt:foreach iterator="item" array="list"> &mvt:item;<br> </mvt:foreach>
 

Basket #52185

Created: 1500917824
View "Basket #52185"
<!-- To read in all custom basket fields as an array use an empty string --> <mvt:item name="customfields" param="Read_Basket( '' )" /> <mvt:foreach iterator="basket" array="customfields"> &mvte:basket:code; - &mvte:basket:value;<br/> </mvt:foreach>
 

Basket #51976

Created: 1500667112
View "Basket #51976"
<mvt:assign name="l.settings:number" value="3.1456478" /> <mvt:assign name="l.settings:number_rounded" value="rnd(l.settings:number, 2)" /> &mvt:number; <br /> &mvt:number_rounded;
 

Basket #51949

 mivascript  operators  NOT  ROUND  CRYPT  MOD  POW  math  string  IN  CIN  EIN  ECIN  EQ  LT  LE  GT  GE  ISNULL  AND  OR
Created: 1500641297
View "Basket #51949"
<!-- To read in all custom basket fields as an array use an empty string --> <mvt:item name="customfields" param="Read_Basket( '' )" /> <mvt:foreach iterator="basket" array="customfields"> &mvte:basket:code; - &mvte:basket:value;<br/> </mvt:foreach>
 
View "Snippet: 1500566990 - v2"
<mvt:assign name="g.array[1]" value=" 'apple' "/> <mvt:assign name="g.array[2]" value=" 'orange' "/> <mvt:assign name="g.array[3]" value=" 'banana' "/> &mvt:global:array; <mvt:assign name="g.randomFruit" value="g.array[ random( miva_array_max(g.array) ) ]" /> &mvte:global:randomFruit; <mvt:assign name="l.settings:number" value="random(3)" /> &mvt:number;
 

Basket #51494

Methods for splitting strings to arrays
Created: 1500068671
View "Basket #51494"
<mvt:assign name="g.string" value="'one|two|three|four|five|six'" /> <h3>Split String mvt:do</h3> <p>Does not inherently support multi-character splitting, you'd have to perform a glosub first (see next example)</p> <mvt:do file="g.Module_Library_Utilities" name="l.success" value="SplitString( g.string, '|', g.splitString )" /> <!-- @@ &mvt:global:MvDO_Error; --> <mvt:foreach iterator="line" array="global:splitString"> &mvt:line;</br> </mvt:foreach> <br> <h3>Deserialize+Global Substitution</h3> <p>This method supports multi-character splitting, as you're just replacing your seperator with a single comma</p> <mvt:assign name="g.array" value="miva_array_deserialize( glosub(g.string,'|',',') )" /> <mvt:foreach iterator="line" array="global:array"> &mvt:line;</br> </mvt:foreach> <mvt:assign name="g.randomNumber" value="random(99)" /> &mvt:global:randomNumber;
 

Basket #51479

Created: 1500050312
View "Basket #51479"
<mvt:assign name="l.settings:array" value="miva_array_deserialize( '1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16' )" /> <mvt:foreach iterator="item" array="array"> <mvt:assign name="g.tempRand" value="random(miva_array_elements(l.settings:array)-1)+1" /> <mvt:assign name="g.tempVal" value="l.settings:item" /> <mvt:assign name="l.settings:item" value="l.settings:array[g.tempRand]" /> <mvt:assign name="g.tempCounter" value="1" /> <mvt:foreach iterator="subItem" array="array"> <mvt:if expr="g.tempCounter EQ g.tempRand"> <mvt:assign name="l.settings:subItem" value="g.tempVal" /> <mvt:foreachstop /> </mvt:if> <mvt:assign name="g.tempCounter" value="g.tempCounter+1" /> </mvt:foreach> </mvt:foreach> &mvt:array;
 

Basket #50015

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: 1499963155
View "Basket #50015"
<mvt:eval expr="1 + 2" /> <hr>
 

practice

Created: 1499879803
View "practice"
<h2>Practice</h2> <hr> <mvt:assign name="g.valval" value="'global val'" /> <strong>g.valval</strong> = &mvt:global:valval; <hr> <mvt:assign name="l.settings:valval2" value="'local val'" /> <strong>l.settings:valval2</strong> = &mvt:valval2; <hr> 1+2 = <mvt:eval expr="(1 + 2)" /> <br><br> 3/2 = <mvt:eval expr="(3 / 2)" /> <br><br> 3/1.5 = <mvt:eval expr="(3 / 1.5)" /> <br><br> (1 + 2) / (3 / 2) * 10 = <mvt:eval expr="(1 + 2) / (3 / 2) * 10" /> <br><br> 98 w/ 12% = <mvt:eval expr="98 - (98 * 0.12)" /> <br><br>
 

Basket #44990

Created: 1499811001
View "Basket #44990"
<mvt:assign name="l.one" value="'1'" /> <mvt:assign name="l.two" value="'2'" /> <mvt:assign name="l.settings:total" value="l.one + l.two" /> &mvt:total;
 

Basket #50658

Created: 1499789175
View "Basket #50658"
<h2>Practice</h2> <hr> <mvt:assign name="g.valval" value="'global val'" /> <strong>g.valval</strong> = &mvt:global:valval; <hr> <mvt:assign name="l.settings:valval2" value="'local val'" /> <strong>l.settings:valval2</strong> = &mvt:valval2; <hr> 1+2 = <mvt:eval expr="(1 + 2)" /> <br><br> 3/2 = <mvt:eval expr="(3 / 2)" /> <br><br> 3/1.5 = <mvt:eval expr="(3 / 1.5)" /> <br><br> (1 + 2) / (3 / 2) * 10 = <mvt:eval expr="(1 + 2) / (3 / 2) * 10" /> <br><br> 98 w/ 12% = <mvt:eval expr="98 - (98 * 0.12)" /> <br><br>
 

Basket #50544

[Documentation](http://www.miva.com/template-language/miva_template_language/entities_&_encoding.html) [Tutorial](http://www.miva.com/videos/web_developers/entities)
Created: 1499383922
View "Basket #50544"
<mvt:assign name="g.array[1]" value=" 'apple' "/> <mvt:assign name="g.array[2]" value=" 'orange' "/> <mvt:assign name="g.array[3]" value=" 'banana' "/> &mvt:global:array; <br> <mvt:assign name="g.randomFruit" value="g.array[ random( miva_array_max(g.array) ) ]" /> &mvte:global:randomFruit; <mvt:assign name="l.settings:number" value="random(3)" /> &mvt:number;
 

Basket #47909

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: 1498584880
View "Basket #47909"
<mvt:assign name="l.sum" value="1 + 2" /> The sum is: &mvt:sum;
 

Updating order array order_status from Pending to In Progress

Simply changes any order_Status that is "Pending" to "In Progress"
Created: 1498090111
View "Updating order array order_status from Pending to In Progress"
<mvt:comment> | | By http://www.scotsscripts.com | </mvt:comment> <mvt:assign name="l.settings:order[1]:id" value="'1'" /> <mvt:assign name="l.settings:order[1]:order_status" value="'In Progress'" /> <mvt:assign name="l.settings:order[2]:id" value="'2'" /> <mvt:assign name="l.settings:order[2]:order_status" value="'In Progress'" /> <mvt:assign name="l.settings:order[3]:id" value="'3'" /> <mvt:assign name="l.settings:order[3]:order_status" value="'Pending'" /> <mvt:assign name="l.settings:order[4]:id" value="'4'" /> <mvt:assign name="l.settings:order[4]:order_status" value="'In Progress'" /> <p><b>Original:</b></p> <mvt:foreach iterator="item" array="order"> id: &mvt:item:id; status: &mvt:item:order_status;<br> </mvt:foreach> <mvt:assign name="l.elements" value="miva_array_elements(l.settings:order)" /> <mvt:while expr="l.counter LT l.elements"> <mvt:assign name="l.counter" value="l.counter + 1" /> <mvt:assign name="l.struct" value="l.settings:order[l.counter]" /> <mvt:if expr="tolower(l.struct:order_status) EQ 'pending'"> <mvt:assign name="l.struct:order_status" value="'In Progress'" /> </mvt:if> <mvt:assign name="l.success" value="miva_array_insert( l.settings:temp_array, l.struct, -1 )" /> </mvt:while> <mvt:assign name="l.settings:order" value="l.settings:temp_array" /> <p><b>Updated:</b></p> <mvt:foreach iterator="item" array="order"> id: &mvt:item:id; status: &mvt:item:order_status;<br> </mvt:foreach>
 

Basket #47956

Created: 1497964333
View "Basket #47956"
<mvt:comment> <!-- Welcome to Miva <snippets/> You can enter standalone blocks of Miva template code then Run or Save your code to see the result. Try inserting a snippet by clicking an Insert from the left or select the Learn/Browse menu items to see some examples --> </mvt:comment>
 
View "miva_array_delete() within mvt:foreach"
<h1>miva_array_delete() within mvt:foreach</h1> <mvt:assign name="l.settings:example:list[1]" value="'Bananas'" /> <mvt:assign name="l.settings:example:list[2]" value="'Milk'" /> <mvt:assign name="l.settings:example:list[3]" value="'Bread'" /> <mvt:assign name="l.settings:example:list[4]" value="'Cereal'" /> <h4>Before:</h4> <mvt:eval expr="decodeattribute(glosub(miva_array_serialize(l.settings:example), ',', '<br>'))" /> <mvt:foreach iterator="item" array="example:list"> <mvt:if expr="l.settings:item EQ 'Milk'"> <mvt:assign name="l.result" value="miva_array_delete( l.settings:example:list, l.POS1, 1 )" /> </mvt:if> </mvt:foreach> <h4>After:</h4> <mvt:eval expr="decodeattribute(glosub(miva_array_serialize(l.settings:example), ',', '<br>'))" />
 

Basket #47914

Created: 1497900663
View "Basket #47914"
<div class="column whole cart-contents"> <div class="row all-hidden medium-all-shown basket-header-row"> <div class="column one-eighth">Order #</div> <div class="column one-eighth">Order Date</div> <div class="column one-eighth align-right">Order Total</div> <div class="column one-fourth">Order Status</div> <div class="column three-eighths">Shipments</div> </div> <mvt:foreach iterator="order" array="orders"> <mvt:assign name="l.settings:list[1]" value="'Order #'" /> <mvt:assign name="l.settings:list[2]" value="'Order Date'" /> <mvt:assign name="l.settings:list[3]" value="'Shipment'" /> <mvt:do file="g.module_library_utilities" name="l.null" value="QuickSortArray(l.settings:list, '', -1)" /> <div class="row basket-product-row"> <div class="column half medium-one-eighth"><strong class="medium-all-hidden">Order # </strong>&mvt:order:id;</div> <div class="column half medium-one-eighth"><strong class="medium-all-hidden">Date: </strong>&mvt:order:date_formatted;-1</div> <div class="column half medium-one-eighth medium-align-right"><strong class="medium-all-hidden">Total: </strong>&mvt:order:formatted_total;</div> <div class="column half medium-one-fourth"><strong class="medium-all-hidden">Status: </strong>&mvt:order:order_status;</div> <div class="column three-fourths medium-one-fourth"> <strong class="medium-all-hidden">Shipments: </strong> <mvt:foreach iterator="shipment" array="order:shipments"> &mvt:shipment:tracklink;<br /> </mvt:foreach> </div> <div class="column one-fourth medium-one-eighth align-center"><a href="&mvt:global:secure_sessionurl;Screen=ORDS&amp;Store_Code=&mvta:global:Store_Code;&amp;SortBy=&mvta:global:SortBy;&amp;Offset=&mvta:global:Offset;&amp;Order_ID=&mvt:order:id;&amp;Order_BillEmail=&mvte:global:Order_BillEmail;&amp;Order_BillZip=&mvte:global:Order_BillZip;" class="button button-mini bg-gray charcoal uppercase">View</a></div> </div> </mvt:foreach> </div> <mvt:if expr="(g.Offset OR g.NextOffset) AND (l.settings:orderhistory_list:per_page NE 0)"> <mvt:if expr="g.Offset EQ 0"> <div class="column half">&nbsp;</div> <mvt:else> <form method="post" action="&mvt:global:secure_sessionurl;" class="column half"> <input type="hidden" name="Screen" value="&mvte:global:Screen;" /> <input type="hidden" name="Store_Code" value="&mvte:global:Store_Code;" /> <input type="hidden" name="SortBy" value="&mvte:global:SortBy;" /> <input type="hidden" name="Order_BillEmail" value="&mvte:global:Order_BillEmail;" /> <input type="hidden" name="Order_BillZip" value="&mvte:global:Order_BillZip;" /> <input type="hidden" name="Offset" value="&mvte:global:PrevOffset;" /> <mvt:item name="buttons" param="Previous" /> </form> </mvt:if> <mvt:if expr="g.NextOffset EQ 0"> <div class="column half">&nbsp;</div> <mvt:else> <form method="post" action="&mvt:global:secure_sessionurl;" class="column half align-right"> <input type="hidden" name="Screen" value="&mvte:global:Screen;" /> <input type="hidden" name="Store_Code" value="&mvte:global:Store_Code;" /> <input type="hidden" name="SortBy" value="&mvte:global:SortBy;" /> <input type="hidden" name="Order_BillEmail" value="&mvte:global:Order_BillEmail;" /> <input type="hidden" name="Order_BillZip" value="&mvte:global:Order_BillZip;" /> <input type="hidden" name="Offset" value="&mvte:global:NextOffset;" /> <mvt:item name="buttons" param="Next" /> </form> </mvt:if> </mvt:if>
 

Basket #47499

Created: 1497557673
View "Basket #47499"
<mvt:assign name="g.price" value="3.25"/> <mvt:do name="g.low_price_formatted" file="g.Module_Root $ g.Store:currncy_mod:module" value="CurrencyModule_AddFormatting( g.Store:currncy_mod, g.price )" /> &mvt:global:low_price_formatted;
 
View "Basket #47367"
<mvt:assign name="g.cc_num_dirty" value="'44a44-5555/3333A1111-adasdsadasdas!'" /> <mvt:while expr="l.character_counter LT len(g.cc_num_dirty)"> <mvt:assign name="l.character_counter" value="l.character_counter + 1" /> <mvt:assign name="l.character" value="substring_var( g.cc_num_dirty, l.character_counter, 1 )"/> <mvt:if expr="isdigit(l.character)"> <mvt:if expr="l.digit_counter GT 0 AND l.digit_counter MOD 4 EQ 0"> <mvt:assign name="g.cc_num_clean" value="g.cc_num_clean $ '-'" /> </mvt:if> <mvt:assign name="g.cc_num_clean" value="g.cc_num_clean $ l.character" /> <mvt:assign name="l.digit_counter" value="l.digit_counter + 1" /> </mvt:if> </mvt:while> abc &mvte:global:cc_num_clean;
 

Basket #47334

Created: 1497388532
View "Basket #47334"
<mvt:do name="l.result" file="g.Module_Root $ g.Store:currncy_mod:module" value="CurrencyModule_AddFormatting( g.Store:currncy_mod, 1.25 )" />
 

Basket #47331

Created: 1497385891
View "Basket #47331"
<mvt:assign name="l.settings:basksum" value="62.95"/> <mvt:assign name="l.settings:qualifier" value="100.00"/> <hr> <mvt:eval expr="(10-5)"/> <hr> <mvt:eval expr="l.settings:qualifier - l.settings:basksum "/>
 
View "Basket #47284"
<mvt:assign name="l.settings:attributes[1]:template_code" value="'size'" /> <mvt:assign name="l.settings:attributes[1]:prompt" value="'Select a Size:'" /> <mvt:assign name="l.settings:attributes[2]:template_code" value="'color'" /> <mvt:assign name="l.settings:attributes[2]:prompt" value="'Select a Color:'" /> <mvt:assign name="l.settings:attributes[3]:template_code" value="'foo'" /> <mvt:assign name="l.settings:attributes[3]:prompt" value="'Foo Bar:'" /> <mvt:assign name="l.settings:attributes[4]:template_code" value="'baz'" /> <mvt:assign name="l.settings:attributes[4]:prompt" value="'Baz!:'" /> <mvt:assign name="g.var" value="'color'" /> POS: <mvt:eval expr="miva_array_search( l.settings:attributes, 1, l.attribute, 'l.attribute:template_code EQ \'' $ g.var $ '\'' )" /> <mvt:eval expr="l.attribute"/>
 

Basket #47045

Created: 1497013667
View "Basket #47045"
<mvt:assign name="g.foo" value="'bar'" /> &mvte:global:foo;<mvt:eval expr="2 + 2" />
 
View "Miva Template Language New Array and Sort Example"
<mvt:comment> | | By http://www.scotsscripts.com | </mvt:comment> <mvt:assign name="l.settings:list[1]:name" value="'apples'" /> <mvt:assign name="l.settings:list[1]:kind" value="'mac'" /> <mvt:assign name="l.settings:list[1]:color" value="'a'" /> <mvt:assign name="l.settings:list[2]:name" value="'bananas'" /> <mvt:assign name="l.settings:list[2]:kind" value="'South American'" /> <mvt:assign name="l.settings:list[2]:color" value="'C'" /> <mvt:assign name="l.settings:list[3]:name" value="'orange'" /> <mvt:assign name="l.settings:list[3]:kind" value="'Florida'" /> <mvt:assign name="l.settings:list[3]:color" value="'b'" /> <mvt:assign name="l.settings:list[4]:name" value="'orange'" /> <mvt:assign name="l.settings:list[4]:kind" value="'Michigan'" /> <mvt:assign name="l.settings:list[4]:color" value="'d'" /> <h2>Before</h2> <mvt:foreach iterator="item" array="list"> name: &mvt:item:name;<br> kind: &mvt:item:kind;<br> color: &mvt:item:color;<br> <hr/> </mvt:foreach> <mvt:comment> | | while loop to create new array and add colorsort field | </mvt:comment> <mvt:assign name="l.elements" value="miva_array_elements(l.settings:list)" /> <mvt:while expr="l.counter LT l.elements"> <mvt:assign name="l.counter" value="l.counter + 1" /> <mvt:assign name="l.struct" value="l.settings:list[l.counter]" /> <mvt:assign name="l.struct:colorsort" value="toupper(l.struct:color)" /> <mvt:assign name="l.success" value="miva_array_insert( l.settings:newlist, l.struct, -1 )" /> </mvt:while> <mvt:comment> | |copy new array to original, sort, and display new list | </mvt:comment> <mvt:assign name="l.settings:list" value="l.settings:newlist" /> <mvt:do file="g.module_library_utilities" name="l.success" value="QuickSortArray(l.settings:list,':colorsort', 1)" /> <h2>After Sort</h2> <mvt:foreach iterator="item" array="list"> name: &mvt:item:name;<br> kind: &mvt:item:kind;<br> color: &mvt:item:color;<br> colorSort: &mvt:item:colorSort; <hr/> </mvt:foreach>