Generating wrapped next/previous entry links
  • I'm trying to generate links to the next and previous entry when looking at a particular entry in a collection.

    So far I'm able to generate the next and previous links but I'm struggling on how to link the next link of the last item to the first item in the collection.

    <v:section path="prev()">
    Previous: <v:a><v:text path="name" /></v:a>
    </v:section>
    <v:section path="next()">
    Next: <v:a><v:text path="name" /></v:a>
    </v:section>


    Any ideas?

  • 3 Answers sorted by
  • You could do:

    <v:if path="next()">
    <v:section path="next()">
    Next: <v:a><v:text path="name" /></v:a>
    </v:section>
    </v:if>
    <v:else>
    <v:section path="/collection_name">
    First: <v:a><v:text path="name" /></v:a>
    </v:section>
    </v:else>

    ... that would wrap it back to the first. Make sense?

  • That worked like a charm, here's the final implementation for anyone else looking to do this:


    <nav class="pagination">
    <v:if path="prev()">
    <v:section path="prev()">
    <v:a rel="prev"><v:text path="name" /></v:a>
    </v:section>
    </v:if>
    <v:else>
    <v:collection path="/employees" limit="1" order="DESC()">
    <v:a rel="prev"><v:text path="name" /></v:a>
    </v:collection>
    </v:else>

    <v:if path="next()">
    <v:section path="next()">
    <v:a rel="next"><v:text path="name" /></v:a>
    </v:section>
    </v:if>
    <v:else>
    <v:collection path="/employees" limit="1">
    <v:a rel="next"><v:text path="name" /></v:a>
    </v:collection>
    </v:else>
    </nav>


    While we're on the subject of collections, is there a way to know the current position of the current context in relation to its parent? I'd like to print the index of each item in a list. Also I'd like to know when I'm processing the last item in a collection.

  • I'm still struggling trying to find the current item position in a collection loop, so far I'm using the following ugly PHP hack:

    <v:php>
    $context->position = $position = $position ? $position + 1 : 1;
    </v:php>


    Does anyone know if there's another way to retrieve the current items position for something like a highscore list?

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Apply for Membership

In this Discussion