More Array Conditionals in Templates

Feature Requests
  • #1

    These two conditions would be particularly useful:

    • True if the current iteration is the n-th interation (rather than just @first and @last)
    • True every n iterations, for example:

    1st iteration: false
    2nd iteration: false
    3rd iteration: true
    4th iteration: false
    5th iteration: false
    6th iteration: true
    7th iteration: false
    etc. etc.

  • #2

    I'm not too sure if we should be adding too much logic in the templates (gets super messy). That said, there is a way for you to accomplish the above, via helpers.

    JS:

    templates.registerHelper('iterateFn', function(data, iterator, total) {
        return (data.someVar && iterator === 3) ? true : false;
    });
    

    Templates:

    <!-- BEGIN someLoop -->
    {function.iterateFn}
    <!-- END someLoop -->
    

    Some real-world examples found here (none using the iterator variable as of yet though)


Suggested Topics


  • 0 Votes
    2 Posts
    216 Views

  • 0 Votes
    4 Posts
    1879 Views

  • Consolidation of template languages

    Unsolved Feature Requests
    2 Votes
    5 Posts
    1772 Views

  • 0 Votes
    6 Posts
    2265 Views

  • 0 Votes
    2 Posts
    1528 Views

| | | |