We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38286
    • 13 Posts
    Anyone know how to use the modulus input modifier?

    I have tried the code below and understand it defaults to %2. I cannot understand how to override it and code it for %4. idx ranges from 1-14 in my chunk template.

    [[+idx:mod:is=`0`:then=`<div class="clear"></div>`]]

    ( this one always returns 0)

    I have also tried

    [[+idx:%4:is=`0`:then=`<div class="clear"></div>`]]


    and

    [[+idx:mod%4:is=`0`:then=`<div class="clear"></div>`]]
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      If this is to have four items in a row, simply float them and give them width and margins so that only four will fit in a row. They'll automatically line up in nice, neat rows.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 3749
        • 24,544 Posts
        I know this works:

        [[+idx:modulus:is=`1`:then=`Odd`:else=`Even`]]


        Here's the code::

        <?php
        case 'modulus':
        case 'mod':
              /* Returns the option modulus on input (default: %2, returns 0 or 1) */
              if (empty($m_val))
                      $m_val = 2;
              $output = (float)$output % (float)$m_val;
              break;


        I'm guessing something like this:

        [[+idx:modulus=`4`:is=`0`:then=`Divisible by 4`:else=`Not divisible by 4`]]




        ---------------------------------------------------------------------------------------------------------------
        PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
        MODX info for everyone: http://bobsguides.com/modx.html
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 38286
          • 13 Posts
          sottwell - I originally did it purely with css but they were not lining up because a height was not set and I was not going to be adding one. I am sure I was doing it wrong still hahaha

          Bob - Your last one worked just great. It didn't at first due to a caching issue, but it does now so thank you.
            • 3749
            • 24,544 Posts
            I'm glad it worked for you. Thanks for reporting back. smiley


            ---------------------------------------------------------------------------------------------------------------
            PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
            MODX info for everyone: http://bobsguides.com/modx.html
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting