We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 43864
    • 151 Posts
    I want to use a counter in a wayfinder so I can use a different style to each element. The example makes it clear, I want this:
    <ul>
    <li class="item1">first item</li>
    <li class="item2">second item</li>
    <li class="item3">third item</li>
    <li class="item4">fourth item</li>
    <li class="item5">fifth item</li>
    ...
    </ul>

    I have this:
    [[Wayfinder? &startId=`0` &rowTpl=`Row` &rowIdPrefix =`item`]]

    And then in the chunk Row:
    <li [[+wf.id]][[+wf.classes]]><a href="[[+wf.link]]" title="[[+wf.title]]"><strong>[[+wf.linktext]]</strong></a>
    [[+wf.wrapper]]
    </li>

    But I want the wf.id to be a number that is counted + 1, so for every menu-item wayfinder finds it puts + 1 to the counter. So for the first menu-item wf.id is 1, the second wf.id is 2, etc... It may not use the id's of the pages!
    I want this because my first items in the menu are on the left side, then there's a pic between and then I have the other menu-items. So I must have different css to each item.

    This question has been answered by sitsol_kristof. See the first response.

      • 40387
      • 28 Posts
      <li class="[[+wf.classnames]]-[[+id]">
        • 43864
        • 151 Posts
        That doesn't work. I don't need the id of the document behind it, I want a number that starts with 1 for the first item, 2 for the second, 3 for the third, etc... I don't want the id of the doc because these are not in chronological order.

        With rowIdPrefix I get the word 'item' in front of it, but how to I get a number behind it.
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          I don't believe that Wayfinder has such a counter.
            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
            • 43864
            • 151 Posts
            But isn't wayfinder going trought some kind of a loop? Maybe with a some php like $i++; it can be done? But I don't know how to implement this into a snippet and use it with the wayfinder. Anyone?
            • discuss.answer
              • 43504
              • 1 Posts
              Try to do it with some JQuery like
              $(function() {
                            var i = 1;
                            $('#test').find('li').each(function(){
                                  var current = $(this);
                                  current.attr("class","item" + i);
                                  i = i + 1;
                              });
                      });
              


              Be warned, I haven't tested the code! [ed. note: sitsol_kristof last edited this post 13 years, 5 months ago.]
                "Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe." -- Albert Einstein