Browse All Fiddles


isDigit with Floats

Created: 1495064052
View "isDigit with Floats"
<h2>isDigit</h2> 1=<mvt:eval expr="isdigit(1)" /><br/> 3.14=<mvt:eval expr="isdigit(3.14)" /><br/> <mvt:if expr="NOT isdigit(3.14)"> 3.14 is not a digit </mvt:if> <h2>Custom isFloat</h2> <mvt:assign name="l.settings:tests" value="miva_array_deserialize('!,@,#,$,%,^,a,b,c,d,-1.b,u.3,111111111,-2,-1.5,-1,-0.5,0,0000000.0,0.5,1,1.5,2,,' )" /> <mvt:foreach iterator="test" array="tests"> <mvt:if expr="len(l.settings:test) AND NOT isalpha(l.settings:test) AND (l.settings:test EQ 0 OR l.settings:test/l.settings:test EQ 1)"> <mvt:assign name="l.settings:color" value="'green'" /> <mvt:assign name="l.settings:result" value="'PASS'" /> <mvt:else> <mvt:assign name="l.settings:color" value="'red'" /> <mvt:assign name="l.settings:result" value="'FAIL'" /> </mvt:if> <h2 style="color: &mvt:color;"><code>&mvt:result;: "&mvt:test;"</code></h2> <mvt:comment> <mvt:assign name="l.len" value="len(l.settings:test)" /> <mvt:assign name="l.index" value="1" /> <mvt:while expr="l.index LE l.len"> <mvt:assign name="l.settings:char" value="substring( l.settings:test, l.index, 1 )" /> &mvt:char;<br> <mvt:assign name="l.index" value="l.index + 1" /> </mvt:while> </mvt:comment> </mvt:foreach>
 

Basket #42905

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: 1494377806
View "Basket #42905"
<mvt:assign name="g.sum" value=" 'somehthing '" /> <mvt:assign name="g.more" value=" <mvt:eval expr="g.sum" />',PGA '" /> The sum is: &mvt:global:more;
 

Basket #42796

 date  math
Get the formatted date one week from now.
Created: 1494283731
View "Basket #42796"
<mvt:assign name="g.current_time" value="s.dyn_time_t" /> <mvt:comment><!-- <mvt:assign name="g.timezone_offset" value="'-4'" /> --></mvt:comment> <mvt:assign name="g.timezone_offset" value="'local'" /> <mvt:assign name="g.duration" value="60 * 60 * 24 * 7" /> <mvt:assign name="g.future_time" value="g.current_time + g.duration"/> <mvt:assign name="g.year" value="time_t_year( g.future_time, g.timezone_offset )" /> <mvt:assign name="g.month" value="padl(time_t_month( g.future_time, g.timezone_offset ), 2, 0)" /> <mvt:assign name="g.day" value="padl(time_t_dayofmonth( g.future_time, g.timezone_offset ), 2, 0)" /> <mvt:assign name="g.24hour" value="padl(time_t_hour( g.future_time, g.timezone_offset ), 2, 0)" /> <mvt:assign name="g.min" value="padl(time_t_min( g.future_time, g.timezone_offset ), 2, 0)" /> <mvt:assign name="g.sec" value="padl(time_t_sec( g.future_time, g.timezone_offset ), 2, 0)" /> <mvt:assign name="g.formatted_future_date" value="g.year $ '-' $ g.month $ '-' $ g.day $ ' ' $ g.24hour $ ':' $ g.min $ ':' $ g.sec" /> &mvt:global:formatted_future_date;<br/> &mvt:global:future_time;
 

Basket #41972

Created: 1493764665
View "Basket #41972"
<mvt:if expr="l.settings:image:imagetype:code EQ 'Google2'"> <mvt:assign name="l.settings:Google2Img" value="'https://www.planttherapy.com/mm5/' $ l.settings:image:image:image" /> <mvt:assign name="l.Google2Found" value="'Yes'" /> </mvt:if>
 
View "Basket #40303"
<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="'foo'" /> 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 #40964

Created: 1493154949
View "Basket #40964"
<mvt:assign name="g.timestamp" value="s.dyn_time_t" /> <mvt:assign name="g.timezone_offset" value="-4" /> <mvt:assign name="g.year" value="time_t_year( g.timestamp, g.timezone_offset )" /> <mvt:assign name="g.month" value="padl(time_t_month( g.timestamp, g.timezone_offset ), 2, 0)" /> <mvt:assign name="g.day" value="padl(time_t_dayofmonth( g.timestamp, g.timezone_offset ), 2, 0)" /> <mvt:assign name="g.24hour" value="padl(time_t_hour( g.timestamp, g.timezone_offset ), 2, 0)" /> <mvt:assign name="g.min" value="padl(time_t_min( g.timestamp, g.timezone_offset ), 2, 0)" /> <mvt:assign name="g.sec" value="padl(time_t_sec( g.timestamp, g.timezone_offset ), 2, 0)" /> <mvt:assign name="g.formatted_date" value="g.year $ '-' $ g.month $ '-' $ g.day $ ' ' $ g.24hour $ ':' $ g.min $ ':' $ g.sec" /> Local Timezone = &mvt:global:formatted_date;<br> <mvt:if expr="g.year EQ 2016 AND g.month EQ 12 AND g.day EQ 02"> <mvt:assign name="g.dec1" value=" 'Today is the first.' " /> <mvt:elseif expr="g.year EQ 2016 AND g.month EQ 12 AND g.day EQ 01"> <mvt:assign name="g.dec2" value=" 'Today is the second.' " /> </mvt:if> <mvt:if expr="g.dec1"> Show banner for the first. <mvt:elseif expr="g.dec2"> Show banner for the second. </mvt:if>
 

Basket #40954

Created: 1493143289
View "Basket #40954"
<mvt:assign name="l.settings:list:name" value="miva_array_deserialize('1,2,3,4')"/> <mvt:eval expr="decodeattribute(glosub(miva_array_serialize(l.settings:list), ',', '<br>'))" /><hr>
 
View "Basket #40110"
<mvt:assign name="g.string" value="'three,three,three,four,four'" /> <mvt:do file="g.Module_Library_Utilities" name="l.success" value="SplitString( g.string, ',', l.settings:array )" /> <!-- @@ &mvt:global:MvDO_Error; --> <h3>Continue</h3> <mvt:foreach iterator="item" array="array"> <mvt:if expr="l.settings:item EQ 'three'"> test-three</br> <mvt:foreachcontinue /> </mvt:if> &mvt:item;</br> <mvt:if expr="l.settings:item EQ 'four'"> test-four</br> &mvt:item;</br> <mvt:foreachcontinue /> </mvt:if> </mvt:foreach> <h3>Stop</h3> <mvt:foreach iterator="item" array="array"> <mvt:if expr="l.settings:item EQ 'three'"> <mvt:foreachstop /> </mvt:if> &mvt:item;</br> </mvt:foreach>
 
View "Basket #40204"
<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="'foo'" /> 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 #38567

Created: 1491435664
View "Basket #38567"
<mvt:assign name="l.settings:test" value="this,is,a,test"></mvt:assign> <mvt:eval expr="miva_array_elements(l.settins:test)"/>
 

Basket #38464

Created: 1491335811
View "Basket #38464"
<mvt:assign name="l.settings:checker" value="'http://checkerimages.checkerdist.com/360/' $ g.checkersku $ '/SMALL/small_' $ g.checkersku $ '_01_01.jpg'" /> &mvt:checker;
 

Basket #38467

Created: 1491334216
View "Basket #38467"
<mvt:assign name="g.foo" value="'bar'" /> &mvte:global:foo;<mvt:eval expr="2 + 2" /><mvt:while expr="g.counter LT 10"> <mvt:assign name="g.counter" value="g.counter + 1" /> &mvte:global:counter;<br> </mvt:while>
 

Snippet: 1490660523 - v2

[Video Tutorial](http://www.miva.com/videos/web_developers/structures) Structures are a lot like arrays.
Created: 1490660534
View "Snippet: 1490660523 - v2"
<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[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'" /> &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[1]:abbr" value="'CA'" /> <mvt:assign name="l.settings:example:states[1]:name" value="'California'" /> <mvt:assign name="l.settings:example:states[2]:abbr" value="'FL'" /> <mvt:assign name="l.settings:example:states[2]:name" value="'Florida'" /> &mvt:example:states[1]:abbr; - &mvt:example:states[1]:name;<br> &mvt:example:states[2]:abbr; - &mvt:example:states[2]: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>'))" />
 

Basket #37271

Created: 1490299644
View "Basket #37271"
<mvt:assign name="g.tip1" value=" '<script>alert(1);</script>' "/> 1:&mvt:global:tip1;<br/> <mvt:assign name="g.tip2" value=" '<script>alert(2);</script>' "/> 2:&mvte:global:tip2;<br/>
 

Basket #37172

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: 1490213431
View "Basket #37172"
<mvt:do name="l.settings:category_count" file="g.Module_Library_DB" value="Runtime_CategoryList_Load_All( l.settings:categories )" /> <mvt:foreach iterator="category" array="categories"> &mvt:category:code;<br> &mvt:category:name;<br> </mvt:foreach>
 

Referencing Variables without "g." or "l."

It is best to always specify a variable scope ("g." or "l."), but it's good to know how Miva will behave too. If you reference a variable without "g." or "l.", then Miva will look for a corresponding "l." variable. If the "l." variable doesn't exist, then it will look for the corresponding "g." variable. The order of the global or local variable Assignments does not matter.
Created: 1490132261
View "Referencing Variables without "g." or "l.""
<h1>Referencing Variables without "g." or "l."</h1> <h2>Summary</h2> <p><em>It is best to always specify a variable scope ("g." or "l."), but it's good to know how Miva will behave...</em></p> <p>If you reference a variable without "g." or "l.", then Miva will look for a corresponding "l." variable.<br>If the "l." variable doesn't exist, then it will look for the corresponding "g." variable.</p> <p>The order of the global or local variable Assignments does not matter.</p> <h2>Examples</h2> <h3>When Global Assignment Then Local Assignment</h3> <mvt:assign name="g.test_1" value="'global'" /> <mvt:assign name="l.test_1" value="'local'" /> Miva will use: <b><mvt:eval expr="test_1" /></b> <h3>Local Assignment then Global Assignment</h3> <mvt:assign name="g.test_2" value="'global'" /> <mvt:assign name="l.test_2" value="'local'" /> Miva will use: <b><mvt:eval expr="test_2" /></b> <h3>Just Global Assignment</h3> <mvt:assign name="g.test_3" value="'global'" /> Miva will use: <b><mvt:eval expr="test_3" /></b> <h3>Just Local Assignment</h3> <mvt:assign name="l.test_4" value="'local'" /> Miva will use: <b><mvt:eval expr="test_4" /></b> <h3>Just l.settings Assignment</h3> <mvt:assign name="l.settings:test_5" value="'l.settings'" /> Miva will use: <b><mvt:eval expr="test_5" /></b>
 

Basket #36954

Created: 1490113529
View "Basket #36954"
<mvt:assign name="l.settings:days[1]" value="'Sunday'" /> <mvt:assign name="l.settings:days[2]" value="'Monday'" /> <mvt:assign name="l.settings:days[3]" value="'Tuesday'" /> <mvt:assign name="l.settings:days[4]" value="'Wednesday'" /> <mvt:assign name="l.settings:days[5]" value="'Thursday'" /> <mvt:assign name="l.settings:days[6]" value="'Friday'" /> <mvt:assign name="l.settings:days[7]" value="'Saturday'" /> <mvt:assign name="l.settings:meals[1]" value="'Breakfast'" /> <mvt:assign name="l.settings:meals[2]" value="'Lunch'" /> <mvt:assign name="l.settings:meals[3]" value="'Dinner'" /> <ul> <mvt:foreach iterator="day" array="days"> <li> <h2>&mvt:day;</h2> <div> l.pos1=<mvt:eval expr="g.pos1" /><br> l.count1=<mvt:eval expr="g.count1" /> </div> <ul> <mvt:foreach iterator="meal" array="meals"> <li> <h4>&mvt:meal;</h4> <div> l.pos2=<mvt:eval expr="l.pos2" /><br> l.count2=<mvt:eval expr="l.count2" /> </div> </li> </mvt:foreach> </ul> </li> </mvt:foreach> </ul>
 
View "Miva Assign by Refference"
<mvt:assign name="g.refvar" value="'foobar'" /> <mvt:assign name="{g.refvar}" value="'Hello World'" /> g.refvar=&mvt:global:refvar;<br> g.foobar=&mvt:global:foobar;<br>
 
View "mvt:foreach has l.posN & l.countN"
<mvt:assign name="l.settings:days[1]" value="'Sunday'" /> <mvt:assign name="l.settings:days[2]" value="'Monday'" /> <mvt:assign name="l.settings:days[3]" value="'Tuesday'" /> <mvt:assign name="l.settings:days[4]" value="'Wednesday'" /> <mvt:assign name="l.settings:days[5]" value="'Thursday'" /> <mvt:assign name="l.settings:days[6]" value="'Friday'" /> <mvt:assign name="l.settings:days[7]" value="'Saturday'" /> <mvt:assign name="l.settings:meals[1]" value="'Breakfast'" /> <mvt:assign name="l.settings:meals[2]" value="'Lunch'" /> <mvt:assign name="l.settings:meals[3]" value="'Dinner'" /> <ul> <mvt:foreach iterator="day" array="days"> <li> <h2>&mvt:day;</h2> <div> l.pos1=<mvt:eval expr="l.pos1" /><br> l.count1=<mvt:eval expr="l.count1" /> </div> <ul> <mvt:foreach iterator="meal" array="meals"> <li> <h4>&mvt:meal;</h4> <div> l.pos2=<mvt:eval expr="l.pos2" /><br> l.count2=<mvt:eval expr="l.count2" /> </div> </li> </mvt:foreach> </ul> </li> </mvt:foreach> </ul>
 
View "Snippet: 1489773720 - v1"
<mvt:assign name="l.midnight_est" value="mktime_t( time_t_year( s.time_t, g.Merchant_Local_Timezone ), time_t_month( s.time_t, g.Merchant_Local_Timezone ), time_t_dayofmonth( s.time_t, g.Merchant_Local_Timezone ), 0, 0, 0, g.Merchant_Local_Timezone ) + 86400 - 10800" /> MIDNIGHT: <mvt:eval expr="l.midnight_est" /><br /> SECONDS UNTIL IT EXPIRES: <mvt:eval expr="l.midnight_est - s.time_t" />
 

Tiered Quantities

 math
Created: 1489685840
View "Tiered Quantities"
<mvt:assign name="g.Quantity" value="1049" /> <mvt:assign name="g.Tier" value="1000" /> g.Quantity=&mvte:global:Quantity;<br> g.Tier=&mvte:global:Tier;<br> <h2>// Division & Ceil/Floor</h2> <mvt:assign name="g.Quantity_Rounded_Up" value="ceil(g.Quantity / g.Tier) * g.Tier" /> g.Quantity_Rounded_Up=&mvte:global:Quantity_Rounded_Up;<br> <mvt:assign name="g.Quantity_Rounded_Down" value="floor(g.Quantity / g.Tier) * g.Tier" /> g.Quantity_Rounded_Down=&mvte:global:Quantity_Rounded_Down;<br> <mvt:comment> <!-- <h2>// MOD</h2> <mvt:assign name="g.Remainder" value="g.Quantity MOD g.Tier" /> g.Remainder=&mvte:global:Remainder;<br> <mvt:assign name="g.Rounded_Quantity" value="g.Quantity - g.Remainder" /> g.Rounded_Quantity=&mvte:global:Rounded_Quantity;<br> <mvt:assign name="g.Final_Quantity" value="g.Rounded_Quantity + g.Tier" /> g.Final_Quantity=&mvte:global:Final_Quantity;<br> --> </mvt:comment>