All Low add-ons are now owned by EEHarbor. Read the blog post.

Support archive

Switch function of a matrix field

Pibble 5 Feb 2014 11:14 problem, complete

Hi
I'm trying to use a matrix field within low_variables. I have a problem with the switch function from matrix because it does not work in connection with low variables:

 
{exp:low_variables:pair var="insuranceclub:conditions_banker"}
<li class="{switch='even|odd'}">
{description}
</li>
{/exp:low_variables:pair}

I'm only getting "even". Do you know why it does not work?

Regards

Replies

  1. Low 5 Feb 2014 11:21

    I'm afraid this is more a Matrix issue than a LV issue, since LV just calls the Matrix functions, which returns the parsed content. Have you asked P&T about this?

  2. Pibble 5 Feb 2014 11:25

    Wow! First of all thanks for the very fast reply!

    so the parsed content is

     
    <li class="even">first description</li>
    <li class="even">second description</li>
    <li class="even">third description</li>


    I tried it with another matrix field I have in a channel and there I get the suggested result:

     
    <li class="even">first description</li>
    <li class="odd">second description</li>
    <li class="even">third description</li>


    Regards

  3. Low 5 Feb 2014 11:29

    I would definitely ask Pixel & Tonic about this, and point out this difference in parsing. Again, it's not something LV does itself, it calls Matrix, which takes care of the parsing.

    As an alternative, you might be able to use the Modulus operator instead.

  4. Pibble 5 Feb 2014 13:09

    I'm getting an error using modulus operator:

     
    {exp:low_variables:pair var="insuranceclub:conditions_banker"}
    {if 2 % 2 == 0}modulo!{/if}
    <li class="">
    <div>{description}</div>
    </li>
    {/exp:low_variables:pair}

  5. Low 5 Feb 2014 13:10

    What version of EE are you using?

  6. Pibble 5 Feb 2014 13:13

    EE 2.7.2
    Low variables 2.4.0
    Matrix 2.5.6

  7. Pibble 5 Feb 2014 13:15

    I think there is a problem with nesting the following code:

     
    {exp:channel:entries channel="events" require_entry="yes"}
    {exp:low_variables:pair var="insuranceclub:conditions_banker"}
    {if 2 % 2 == 0}modulo!{/if}
    <li class="">
    <div>{description}</div>
    </li>
    {/exp:low_variables:pair}
    {/exp:channel:entries}

  8. Pibble 5 Feb 2014 13:17

    ok... Using the code with a prefix works for me:

     
    {exp:low_variables:pair var="insuranceclub:conditions_banker" dynamic="no" var_prefix="con"}
    {con:switch='even|odd'}
    <li class="">
    <div>{con:description}</div>
    </li>
    {/exp:low_variables:pair}

  9. Low 5 Feb 2014 13:18

    Ah yes, nesting the tags will give you that behaviour. Glad you solved it now.