We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9207 ☆ A M B ☆
    • 2,475 Posts
    Is there a MODx placeholder in Revo that produces sequential numbers? E.g. if my formatting chunk looked like this:

    [[+serial]], [[+serial]], [[+serial]]


    It’d output:

    1, 2, 3


    That would be cool... in a seriously geeky way. Or is the best way to handle this to use an output filter of some sort?
      • 4385
      • 372 Posts
      Would it reset on refresh? Or is it more like a counter each time it is used?
        DropboxUploader -- Upload files to a Dropbox account.
        DIG -- Dynamic Image Generator
        gus -- Google URL Shortener
        makeQR -- Uses google chart api to make QR codes.
        MODxTweeter -- Update your twitter status on publish.
        • 3749
        • 24,544 Posts
        Do they really need to be a sequence? If all you need is a unique number this snippet will give you a guaranteed unique number (unless you are in a time machine):

        <?php
        return time();
          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
          • 9207 ☆ A M B ☆
          • 2,475 Posts
          I was thinking something that reset for each page request.
          Hmm... perhaps microtime() would be a better candidate as many pages render in less than one second.

          The only reason I hesitate to implement a Snippet solution to this is that I’m worried about any caching, and about parsing Snippet chunks that make use of those Snippet calls. Evo had a lot of problems processing Snippets in chunks, but I think Revo it’d be fine.

          Some uses: tab indexes on forms. I have to think about this a bit more...
            • 3749
            • 24,544 Posts
            You could certainly use a TV and update it’s value on every page load, but that might be even slower.
              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
              • 4385
              • 372 Posts
              try
              serial numbers[[*id:add=`1`]] [[*id:add=`2`]]  [[*id:add=`3`]] 
                DropboxUploader -- Upload files to a Dropbox account.
                DIG -- Dynamic Image Generator
                gus -- Google URL Shortener
                makeQR -- Uses google chart api to make QR codes.
                MODxTweeter -- Update your twitter status on publish.
                • 9207 ☆ A M B ☆
                • 2,475 Posts
                Hmmm... I could do something like this:

                [[+i:seq]]


                I end up needing this a lot when I’m generating complex forms, especially ones that get updated via AJAX (i.e. Javascript). E.g.

                <input type="text" name="array_of_stuff[1][key]" value="some value" />


                The problem is that for some series of elements, the [1] has to stay the same, in order to group a series of values onto the same containing "array_of_stuff", in which case, I’d need an output filter that could identify a group of elements while still incrementing... in other words, the incrementing would have to be paused sometimes.

                <label>First group of elements for record 1</label>
                <input type="text" name="array_of_stuff[ [[+i:seq=`inc`]] ][key1]" value="some value1" />
                <input type="text" name="array_of_stuff[ [[+i:seq]] ][key2]" value="some value2" />
                <input type="text" name="array_of_stuff[ [[+i:seq]] ][key2]" value="some value3" />
                
                <label>Second group of elements for record 2</label>
                <input type="text" name="array_of_stuff[ [[+i:seq=`inc`]] ][key1]" value="some other value1" />
                <input type="text" name="array_of_stuff[ [[+i:seq]] ][key2]" value="some other value2" />
                <input type="text" name="array_of_stuff[ [[+i:seq]] ][key2]" value="some other value3" />
                


                So "normal" usage would be [[+i:seq=`inc`]], which would always increment the counter and return the result, whereas [[+i:seq]] would return the value of the counter. Yeah... I think that’s what I need. Just a basic output filter that doesn’t care what variable it’s filtering because it will overwrite the value.