snippet-1496956502


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>
 

Miva Template Language New Array and Sort Example

Use Miva Template language to sort an existing array by inserting sort keys into the array structure. This is done by creating a new temporary structure with the sort key (colorsort), and then add it to a new array using miva_array_insert(..). When the loop is done, the new temporary array is then copied back into the original array. In miva_array_insert(...) we use -1 for the array index to force it to add the structure to the next array element. Since we are creating a new array, it will be populated from index 1 to the end. We do it this way because there is no other way to add to array structures in the miva template language. Using brackets when trying to add to existing array structures does not work in the miva template language. http://www.scotsscripts.com
Created: 1496961839
View "Miva Template Language New Array and Sort Example"
<mvt:comment>Example 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</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 array</mvt:comment> <mvt:assign name="l.settings:list" value="l.settings:newlist" /> <mvt:comment>sort original array</mvt:comment> <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>
 

Miva Template Language New Array and Sort Example

Use Miva Template language to sort an existing array by inserting sort keys into the array structure. This is done by creating a new temporary structure with the sort key (colorsort), and then add it to a new array using miva_array_insert(..). When the loop is done, the new temporary array is then copied back into the original array. In miva_array_insert(...) we use -1 for the array index to force it to add the structure to the next array element. Since we are creating a new array, it will be populated from index 1 to the end. We do it this way because there is no other way to add to array structures in the miva template language. Using brackets when trying to add to existing array structures does not work in the miva template language. http://www.scotsscripts.com
Created: 1496961811
View "Miva Template Language New Array and Sort Example"
TEST<br><br> <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</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 array</mvt:comment> <mvt:assign name="l.settings:list" value="l.settings:newlist" /> <mvt:comment>sort original array</mvt:comment> <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>
 

Miva Template Language New Array and Sort Example

Use Miva Template language to sort an existing array by inserting sort keys into the array structure. This is done by creating a new temporary structure with the sort key (colorsort), and then add it to a new array using miva_array_insert(..). When the loop is done, the new temporary array is then copied back into the original array. In miva_array_insert(...) we use -1 for the array index to force it to add the structure to the next array element. Since we are creating a new array, it will be populated from index 1 to the end. We do it this way because there is no other way to add to array structures in the miva template language. Using brackets when trying to add to existing array structures does not work in the miva template language. http://www.scotsscripts.com
Created: 1496961745
View "Miva Template Language New Array and Sort Example"
TEST<br><br> <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> <h3>While loop To Create New Array</h3> <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: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>
 
View "Miva Template Language New Array and Sort Example"
TEST<br><br> <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> <h3>While loop To Create New Array</h3> <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: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>
 

Sort Example

Usage of QuickSortArray
Created: 1496956502
View "Sort Example"
<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="SortItem" name="l.null" value="QuickSortArray(l.settings, l.settings:list, -1)" /> <h2>After</h2> <mvt:foreach iterator="item" array="list"> &mvt:item;<br> </mvt:foreach>