Announcement

Collapse
No announcement yet.

foreach array position and foreach break

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

    foreach array position and foreach break

    How do you find the position of an array member in a mvt:foreach loop?

    Is l.pos available in a mvt:foreach loop? I tried a counter variable but can't get it to work logically without a conditional break.

    I've seen this asked before, is there a way to break out from a foreach loop without exiting the script?

    Does miva_array_find() and indexof() only work on stringified arrays?

    Given array structure {[product_id, displ_order]}: { [436,10], [318,21], [791,36] [4,48] } how would I find the position on product_id 318?
    http://www.alphabetsigns.com/

    #2
    Re: foreach array position and foreach break

    1st part of the question:

    I am thinking l.pos1 is holding the index of the outer loop. 1st "nested is l.pos2 etc. But, When I want to display that, I've resorted to assigning that to another var right after the foreach loop initiates.

    Foreach....
    <mvt:assign name="g.cnt1" value="l.pos1" />
    &mvt:global:cnt1;

    To test your position:

    <mvt:if expr="POS1 EQ 4">

    I don't recall if there is a Foreachexit or something like that.

    To find the position in the loop, I'm thinking:

    <mvt:if expr="l.settings:product_id EQ '318'">
    <mvt:assign name="g.currentpos" value="l.pos1" />
    </mvt:if>


    Scott
    Last edited by ids; 07-04-15, 11:59 PM.
    Need to offer Shipping Insurance?
    Interactive Design Solutions https://www.myids.net
    MivaMerchant Business Partner | Certified MivaMerchant Web Developer
    Competitive Rates, Custom Modules and Integrations, Store Integration
    AutoBaskets|Advanced Waitlist Integration|Ask about Shipping Insurance Integration
    My T-shirt Collection is mostly MivaCon T-shirts!!

    Comment


      #3
      Re: foreach array position and foreach break

      Thanks Scott. l.pos1 was there. Everything was easy after that.

      It makes we wonder what other variables are around that I can't find in the l.settings or l.all_settings array. I wonder if it has to do with how the STANDARDOUTPUTLEVEL is set in the LSK.

      I saw in a recent post that a variable wasn't showing in a LATU tool but maybe it's there anyway depending on STANDARDOUTPUTLEVEL settings.

      Thanks again.
      http://www.alphabetsigns.com/

      Comment


        #4
        Re: foreach array position and foreach break

        STANDARDOUTPUT level should only effect HOW variables and content are output. Should have no effect on WHAT variables are present.

        However, there are several things that can effect what variables are visably' present. For example, the tool used (LATU is pretty old and requires separate configuration on every page used), WHERE the tool is loaded and OTHER processes inbetween. For example, if you run say our Inspector module, it loads has the last component element. That means, for example, l.settings:MyFoo:variable could be "boo" at the initialization of the page, and "bar" by the time Inspector see's it cause something has manipulated it.

        So, basically, while invaluable, tools like Inspector have their limitations. (But would definitely recommend upgrading from thinks like LATU Tools.) If you (not you Dan) are really cheap, I think there is another free one somewhere--not as good as Inspector, but if you like working hard for a living, its available :)
        Bruce Golub
        Phosphor Media - "Your Success is our Business"

        Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
        phosphormedia.com

        Comment


          #5
          Re: foreach array position and foreach break

          Dan, you can switch to ours if you want to try free http://apps.miva.com/product/GD-VARIABLES.html
          Sabine Sharp
          eCommerce Strategies & Solutions
          Glendale Designs
          Support Desk
          623.322.6066

          Comment

          Working...
          X