Skip to content


POS1 serves as a built-in loop counter, native to both <mvt:foreach> and <mvt:while> loops, providing developers with the current iteration index within a loop.

POS1 is a special local variable that automatically increments with each iteration of a loop. It represents the current iteration index, starting from 1 and increasing by one with each subsequent iteration. In the case of nested loops, such as one foreach loop within another, the POS1 counter dynamically adjusts to Pos2, Pos3, and so forth, reflecting the level of nesting.


Basic Iteration Output#

<mvt:foreach iterator="product" array="category_listing:products">
    <!-- Output current iteration index -->

Targeting Specific Iteration#

<mvt:foreach iterator="product" array="category_listing:products">
    <!-- Output specific message after the 5th iteration -->
    <mvt:if expr="POS1 EQ 5">
        This is the 5th iteration of the loop.

Targeting Multiples within the Loop:#

This code targets every fourth iteration within the loop, printing a message accordingly.

<mvt:foreach iterator="product" array="category_listing:products">
    <!-- Output specific message for every fourth iteration -->
    <mvt:if expr="POS1 MOD 4 EQ 0">
        This is a multiple of 4.

Handling Nested Loops#

<mvt:foreach iterator="product" array="category_listing:products">
    <!-- Outer Loop -->
    POS1 Value: &mvt:POS1; <br>

    <mvt:foreach iterator="product2" array="category_listing:products">
        <!-- Inner Loop -->
        Pos2 Value: &mvt:pos2; <br>


  • POS1 can only be tested for in if statements. It cannot be output to the screen.
  • POS1 always starts with 1.
  • If you nest foreach loops, every level you go down POS1 becomes POS2, POS3 etc.

The POS1 counter in Miva Merchant’s template language offers a convenient and efficient means to manage loop iterations. By leveraging this built-in feature, developers can streamline loop processing and enhance the functionality of their Miva Merchant templates.