Announcement

Collapse
No announcement yet.

Using <mvt:assign with arrays

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using <mvt:assign with arrays

    I use Toolbelt to sum array elements using and index to the array. but this does not work with mvt:assign, because it does not parse the array index.

    <mvt:item name="ry_toolbelt" param="assign|l.all_settings:totals[g.index]:quantity|l.all_settings:totals[g.index]:quantity + l.all_settings:item:quantity" />

    How would I do this in straight page template language.

    I've used miva_array_insert() to add items to an array, but here I need to sum elements
    Ray Yates
    "If I have seen further, it is by standing on the shoulders of giants."
    --- Sir Isaac Newton

  • I don't think you can assign the sum to an array element, although I have not tested, either way here's how to add those two vars together.

    <mvt:assign name="l.settings:sum" value="l.all_settings:totals[g.index]:quantity + l.all_settings:item:quantity" />

    sum = &mvt:sum;
    M.A.D.* since 1997

    http://www.scotsscripts.com

    *miva application developers

    Comment


    • That's a good suggestion and gets us 1/2 way there. I swear, I worked out how to do that at one point; for the life of me, I can't remember how.
      I was just looking at this command with interest. http://www.mivascript.com/item/miva_...ilter_ref.html

      Ideally we would have support for one of these syntax examples.
      Hint Hint er.. ah... Jon B?
      Code:
      <mvt:assign name="{ l.variable_name }" value="g.total" />    Useful... Create the array structure element as a string assigned to l.variable first
      <mvt:assign name="l.array" index="l.index" member="total" value="g.total" />   Better
      <mvt:assign name="l.array[l.index]:total" value="g.total" />  My personal favorite.
      
      Or alternatively a new string function  miva_reference() would allow us to two step it.
      <mvt:assign name="l.varname" value="miva_reference( 'l.all_settings:totals[g.index]:quantity' )" />
      <mvt:assign name="l.varname" value="g.total" />
      
      Note again Toolbelt: <mvt:item name="ry_toolbelt" param="reference|new_variable_name|old_variable_name" />
      Since the template compiler is a subset of the Miva Script compiler. It should be doable, especially the parsing of [ l.index ]. Any bracket contents [xxx] in the variable name would need to be evaluated just like value="expression"
      Last edited by RayYates; 01-10-19, 06:49 AM.
      Ray Yates
      "If I have seen further, it is by standing on the shoulders of giants."
      --- Sir Isaac Newton

      Comment

      Working...
      X

      This website uses cookies to identify visitors, track visitors to our website, store login session information and to remember your user preferences. By continuing to use this site you agree to our use of cookies. Learn More.

      This website uses cookies. By continuing to use this site you agree to our use of cookies. Learn More.

      Accept