"deserialize" Snippets


View "Basket #48599"
<mvt:assign name="g.string" value="'cat, dog bob edward sally'" /> <mvt:assign name="g.delimiter" value="' '" /> <mvt:do file="g.Module_Library_Utilities" name="l.null" value="SplitString( g.string, g.delimiter, g.array )" /> &mvte:global:array[1];<br> &mvte:global:array[2];<br> &mvte:global:array[3];<br> &mvte:global:array[4];<br> &mvte:global:array[5];<br> <hr/> <mvt:assign name="g.string_again" value="glosub( g.array, ',', '|' )" /> &mvt:global:array;<br> &mvte:global:string_again;<br>
 

Basket #57957

Methods for splitting strings to arrays
Created: 1504715800
View "Basket #57957"
<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 #52503

Methods for splitting strings to arrays
Created: 1501196880
View "Basket #52503"
<mvt:assign name="g.string" value="'asdfasdf'" /> <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:assign name="g.relprod_arr_len" value="miva_array_elements(g.splitString )" /> Cookie recentproductd array length: &mvt:global:relprod_arr_len; <br> <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>
 

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;
 
View "Basket #46802"
<mvt:assign name="l.settings:basket:items[1]:code" value="'doe'" /> <mvt:assign name="l.settings:basket:items[2]:code" value="'ray'" /> <mvt:assign name="l.settings:basket:items[3]:code" value="'mee'" /> <mvt:assign name="l.settings:basket:items[4]:code" value="'fah'" /> <mvt:assign name="l.settings:basket:items[5]:code" value="'soh'" /> <mvt:assign name="l.settings:basket:items[6]:code" value="'lah'" /> <mvt:assign name="l.settings:basket:items[7]:code" value="'tee'" /> <h2>Always at End</h2> <mvt:foreach iterator="item" array="basket:items"> "&mvt:item:code;", </mvt:foreach> <h2>Using POS1</h2> <mvt:foreach iterator="item" array="basket:items"> <mvt:if expr="POS1 EQ 2">,</mvt:if> "&mvt:item:code;" </mvt:foreach> <hr> &mvt:basket:items[4]:code;
 
View "Basket #32640"
<style> #email-popup{ max-width: 449px; min-height: 250px; text-align: center; background: green; padding: 1.5rem; } .popup-line-one{ font-size: 2rem; } .popup-line-two{ font-size: 1.2rem; text-transform: uppercase; } .popup-hr{ height: 1px; background: #000; max-width: 50px; margin: .5rem auto; } .popup-text{ font-size: 1rem; } #popup-form{ width: 100%; } #email-popup input{ border: 1px solid #DEDEDE; width: 100%; height: 42px; } </style> <div id="email-popup"> <div class="popup-line-one">15% Off</div> <div class="popup-line-two">Your first order</div> <div class="popup-hr"></div> <div class="popup-text">Be the first to know about our promotions, limited edition products and other rad stuff!</div> <br /> <form id="popup-form"> <input type="email" placeholder="Enter your email here" /> </form> </div>
 
View "Basket #31387"
<mvt:comment>JSON Data</mvt:comment> <mvt:assign name="l.settings:rotating_img_data" value="'[ { \"name\": \"Product1\", \"number\": \"5003", \"src\": \"http://www.clivecoffee.com/img/bio/ben.png\" }, { \"name\": \"Product1\", \"number\": \"5002", \"src\": \"http://www.clivecoffee.com/images/products/affirm-icon-product-page_2x.png\" }, { \"name\": \"Product1\", \"number\": \"5302", \"src\": \"http://www.clivecoffee.com/images/products/affirm-icon-product-page_2x.png\" }, ]'" /> <mvt:assign name="l.success" value="miva_json_decode(l.settings:rotating_img_data, l.settings:salespersons)" /> <mvt:comment>Assign array length</mvt:comment> <mvt:assign name="l.salespersons_count" value="miva_array_elements( l.settings:salespersons )" /> <mvt:comment>Shuffle array attempt</mvt:comment> Before:<br><mvt:eval expr="decodeattribute(glosub(miva_array_serialize(l.settings:salespersons), ',', '<br>'))" /><br> <mvt:foreach iterator="salesperson" array="salespersons"> <mvt:assign name="g.tempRand" value="random(l.salespersons_count - 1)" /> <mvt:assign name="g.tempVal" value="l.settings:salesperson" /> <mvt:assign name="l.settings:salesperson" value="l.settings:salespersons[g.tempRand]" /> <mvt:assign name="l.settings:salespersons[g.tempRand + 1]" value="g.tempVal" /> </mvt:foreach> After:<br><mvt:eval expr="decodeattribute(glosub(miva_array_serialize(l.settings:salespersons), ',', '<br>'))" /><br>
 
View "Basket #19297"
<mvt:assign name="l.fruit" value="'banana,apple,peach'"/> <mvt:assign name="l.settings:fruits" value="miva_array_deserialize( l.fruit )"/> <mvt:foreach iterator="fruit" array="fruits"> &mvt:fruit;<br> </mvt:foreach>
 

String splitting

Methods for splitting strings to arrays
Created: 1465312162
View "String splitting"
<mvt:assign name="g.string" value="'one|two|three|four|five|six'" /> <h3>Split String mvt:do</h3> <mvt:assign name="g.startTime" value="s.dyn_tm_usec" /> <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>Completed in <mvt:eval expr="s.dyn_tm_usec - g.startTime" /> milliseconds. <hr> <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.startTime" value="s.dyn_tm_usec" /> <mvt:assign name="g.array" value="miva_array_deserialize( glosub(g.string,'|',',') )" /> <mvt:foreach iterator="line" array="global:array"> &mvt:line;</br> </mvt:foreach> </br>Completed in <mvt:eval expr="s.dyn_tm_usec - g.startTime" /> milliseconds. <hr> <h3>Get Token</h3> <p>Doesn't support multi-character splitting, a little harder to read in my opinion</p> <mvt:assign name="g.startTime" value="s.dyn_tm_usec" /> <mvt:assign name="g.nl" value="'|'" /> <mvt:assign name="l.count" value="1" /> <mvt:assign name="l.token" value="gettoken(g.string, g.nl , l.count)" /> <mvt:while expr="NOT ISNULL l.token"> <mvt:assign name="l.array_length" value="miva_array_insert( l.settings:my_array, l.token, -1 )" /> <mvt:assign name="l.count" value="l.count + 1" /> <mvt:assign name="l.token" value="gettoken(g.string, g.nl , l.count)" /> </mvt:while> <mvt:foreach iterator="row" array="my_array"> &mvt:row;</br> </mvt:foreach> </br>Completed in <mvt:eval expr="s.dyn_tm_usec - g.startTime" /> milliseconds. <hr> <h3>New MivaScript Split String</h3> <p>Probably easiest to use</p> <mvt:assign name="g.startTime" value="s.dyn_tm_usec" /> <mvt:assign name="g.array" value="miva_splitstring(g.string, '|', g.array, NULL)" /> <mvt:foreach iterator="row" array="my_array"> &mvt:row;</br> </mvt:foreach> </br>Completed in <mvt:eval expr="s.dyn_tm_usec - g.startTime" /> milliseconds.
 

Basket #16315

Methods for splitting strings to arrays
Created: 1461119732
View "Basket #16315"
<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>
 

Snippet: 1460047868 - v1

Methods for splitting strings to arrays
Created: 1460047868
View "Snippet: 1460047868 - v1"
<mvt:assign name="g.string" value="'one|||two|||three|||four|||five|||six'" /> <h3>Split String mvt:do</h3> <mvt:assign name="g.startTime" value="s.dyn_tm_usec" /> <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>Completed in <mvt:eval expr="s.dyn_tm_usec - g.startTime" /> milliseconds. <hr> <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.startTime" value="s.dyn_tm_usec" /> <mvt:assign name="g.array" value="miva_array_deserialize( glosub(g.string,'|||',',') )" /> <mvt:foreach iterator="line" array="global:array"> &mvt:line;</br> </mvt:foreach> </br>Completed in <mvt:eval expr="s.dyn_tm_usec - g.startTime" /> milliseconds. <hr> <h3>Get Token</h3> <p>Doesn't support multi-character splitting, a little harder to read in my opinion</p> <mvt:assign name="g.startTime" value="s.dyn_tm_usec" /> <mvt:assign name="g.nl" value="'|||'" /> <mvt:assign name="l.count" value="1" /> <mvt:assign name="l.token" value="gettoken(g.string, g.nl , l.count)" /> <mvt:while expr="NOT ISNULL l.token"> <mvt:assign name="l.array_length" value="miva_array_insert( l.settings:my_array, l.token, -1 )" /> <mvt:assign name="l.count" value="l.count + 1" /> <mvt:assign name="l.token" value="gettoken(g.string, g.nl , l.count)" /> </mvt:while> <mvt:foreach iterator="row" array="my_array"> &mvt:row;</br> </mvt:foreach> </br>Completed in <mvt:eval expr="s.dyn_tm_usec - g.startTime" /> milliseconds.
 

String splitting

Methods for splitting strings to arrays
Created: 1460047755
View "String splitting"
<mvt:assign name="g.string" value="'one|two|three|four|five|six'" /> <h3>Split String mvt:do</h3> <mvt:assign name="g.startTime" value="s.dyn_tm_usec" /> <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>Completed in <mvt:eval expr="s.dyn_tm_usec - g.startTime" /> milliseconds. <hr> <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.startTime" value="s.dyn_tm_usec" /> <mvt:assign name="g.array" value="miva_array_deserialize( glosub(g.string,'|',',') )" /> <mvt:foreach iterator="line" array="global:array"> &mvt:line;</br> </mvt:foreach> </br>Completed in <mvt:eval expr="s.dyn_tm_usec - g.startTime" /> milliseconds. <hr> <h3>Get Token</h3> <p>Doesn't support multi-character splitting, a little harder to read in my opinion</p> <mvt:assign name="g.startTime" value="s.dyn_tm_usec" /> <mvt:assign name="g.nl" value="'|'" /> <mvt:assign name="l.count" value="1" /> <mvt:assign name="l.token" value="gettoken(g.string, g.nl , l.count)" /> <mvt:while expr="NOT ISNULL l.token"> <mvt:assign name="l.array_length" value="miva_array_insert( l.settings:my_array, l.token, -1 )" /> <mvt:assign name="l.count" value="l.count + 1" /> <mvt:assign name="l.token" value="gettoken(g.string, g.nl , l.count)" /> </mvt:while> <mvt:foreach iterator="row" array="my_array"> &mvt:row;</br> </mvt:foreach> </br>Completed in <mvt:eval expr="s.dyn_tm_usec - g.startTime" /> milliseconds.
 

String splitting

Methods for splitting strings to arrays
Created: 1460041211
View "String splitting"
<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> <hr> <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> <hr> <h3>Get Token</h3> <p>Doesn't support multi-character splitting, a little harder to read in my opinion</p> <mvt:assign name="g.nl" value="'|'" /> <mvt:assign name="l.count" value="1" /> <mvt:assign name="l.token" value="gettoken(g.string, g.nl , l.count)" /> <mvt:while expr="NOT ISNULL l.token"> <mvt:assign name="l.array_length" value="miva_array_insert( l.settings:my_array, l.token, -1 )" /> <mvt:assign name="l.count" value="l.count + 1" /> <mvt:assign name="l.token" value="gettoken(g.string, g.nl , l.count)" /> </mvt:while> <mvt:foreach iterator="row" array="my_array"> &mvt:row;</br> </mvt:foreach>
 

String splitting

Methods for splitting strings to arrays
Created: 1460040170
View "String splitting"
<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>
 
View "Basket #9702"
<mvt:assign name="g.string" value="'123,312,45,656'" /> <mvt:assign name="g.array" value="miva_array_deserialize( g.string )" /> &mvt:global:array[1];<br> &mvt:global:array[2];<br> &mvt:global:array[3];<br> &mvt:global:array[4];<br> <mvt:assign name="l.settings:fields" value="g.array" /> <mvt:assign name="g.fields_join" value="''" /> <mvt:foreach iterator="field" array="fields"> <mvt:if expr="g.fields_join NE ''"> <mvt:assign name="g.fields_join" value ="g.fields_join $ ','" /> </mvt:if> <mvt:assign name="g.fields_join" value="g.fields_join $ l.settings:field" /> </mvt:foreach> &mvt:global:fields_join;
 

Basket #8353

Methods for splitting strings to arrays
Created: 1449263140
View "Basket #8353"
<mvt:assign name="g.test" value="'one two three four five'" /> <mvt:assign name="g.test2" value="'uno dos tres quatro cinco'" /> <mvt:assign name="g.null" value="miva_splitstring( g.test, ' ', g.array, NULL )" /> <mvt:assign name="g.null" value="miva_splitstring( g.test2, ' ', g.array2, NULL )" /> <mvt:assign name="g.output" value="g.array[1] $ '-' $ g.array[2] $ '-' $ g.array[3] $ '-' $ g.array2[1] $ '-' $ g.array2[2] $ '-' $ g.array2[3]" /> &mvt:global:output;
 
View "Basket #7657"
<mvt:assign name="g.test" value="'caleb'" /> <mvt:assign name="g.test" value="NULL" /> when assigned to NULL (g.NULL empty) : &mvt:global:test;</br></br> <mvt:assign name="l.NULL" value="3" /> <mvt:assign name="g.test" value="NULL" /> when assigned to NULL (g.NULL value) : &mvt:global:test;</br></br> <mvt:assign name="g.test" value="''" /> when assigned to empty string: &mvt:global:test;</br></br>
 
View "Split/Explode String into Array"
<mvt:assign name="g.string" value="'1|2|3|4|5'" /> <mvt:assign name="g.delimiter" value="'|'" /> <mvt:do file="g.Module_Library_Utilities" name="l.null" value="SplitString( g.string, g.delimiter, g.array )" /> &mvte:global:array[1];<br> &mvte:global:array[2];<br> &mvte:global:array[3];<br> &mvte:global:array[4];<br> &mvte:global:array[5];<br> <hr/> <mvt:assign name="g.string_again" value="glosub( g.array, ',', '|' )" /> &mvt:global:array;<br> &mvte:global:string_again;<br>
 
View "Split/Explode String into Array"
<mvt:assign name="g.string" value="'1|2|3|4|5'" /> <mvt:assign name="g.delimiter" value="'|'" /> <mvt:do file="g.Module_Library_Utilities" name="l.null" value="SplitString( g.string, g.delimiter, g.output_array )" /> &mvte:global:output_array[1];<br> &mvte:global:output_array[2];<br> &mvte:global:output_array[3];<br> &mvte:global:output_array[4];<br> &mvte:global:output_array[5];<br>
 
View "Split/Explode String into Array"
<mvt:assign name="g.string" value="'1,2,3,4,5'" /> <mvt:assign name="g.array" value="miva_array_deserialize( g.string )" /> &mvt:global:array[1];<br> &mvt:global:array[2];<br> &mvt:global:array[3];<br> &mvt:global:array[4];<br> &mvt:global:array[5];<br>
 
View "Basket #6092"
<mvt:assign name="l.fruit" value="'banana,apple,peach,test'"/> <mvt:assign name="l.settings:fruits" value="miva_array_deserialize( l.fruit )"/> <mvt:foreach iterator="fruit" array="fruits"> &mvt:fruit;<br> </mvt:foreach>
 
View "Miva Array Deserialize "
<mvt:assign name="l.fruit" value="'banana,apple,peach'"/> <mvt:assign name="l.settings:fruits" value="miva_array_deserialize( l.fruit )"/> <mvt:foreach iterator="fruit" array="fruits"> &mvt:fruit;<br> </mvt:foreach>
 

Basket #1319

[Video Tutorial](http://www.miva.com/videos/web_developers/structures) Structures are a lot like arrays.
Created: 1430861164
View "Basket #1319"
<mvt:assign name="l.serialized" value="':customfields:aromaticScent=Peppermint+Western+U.S.+essential+oil+has+a+fresh%2C+cool%2C+grassy-minty+scent+that+is+cleaner%2C+smoother%2C+and+more+refined+than+Indian+Peppermint.,:customfields:extractionMethod=Steam+Distilled,:customfields:product_type=Essential+Oil,:customfields:size=10+ml+%281%2F3+oz%29,:customfields:strengthOfAroma=Strong'" /> <mvt:assign name="l.serialized" value="l.serialized $ ',:customfields:strengthOfAroma=Weak'" /> <mvt:assign name="l.settings:deserialized" value="miva_array_deserialize( l.serialized )" /> &mvt:deserialized:customfields:strengthOfAroma;
 
View "Basket #315"
<mvt:assign name="g.string" value="'1600cc'" /> <mvt:assign name="g.search" value="'cc'" /> <mvt:assign name="g.foo" value="indexof( g.search, g.string, 1 )" /> &mvte:global:foo;