How to Link to the prev/next Document?

Hey there,

I have defined my own Subpages (Neos.Neos:Document). Now I need to integrate two buttons to go to the prev and next Document, if there is one.

I can’t really find a useful example. While I am trying to use the Flow-Query: next() it gives me weird results:

  next = Neos.Fusion:Tag {
      @process.tmpl = ${'<div class="prev"><em>' + value + '</em></div>'}
      tagName = 'a'
      attributes.href = NodeUri {
          node = ${q(node).next()}
      }
      content = ${q(node).next().property('title')}
  }      

The weird thing here is, that in the case of the property title, I am getting the correct title of the next Document, on the other hand, the created link wrongly points to the active Document (and not the next one).

Could somebody please explain this behavior and tell me what I need to do differently?

Thanks!
Robin

Hi @webappcreations,

you probably have to use get(0) on the result to make that work as in:

node = ${q(node).next().get(0)}

What about the Neos.Demo site: Neos.Demo/Resources/Private/Fusion/Root.fusion at 8.2 · neos/Neos.Demo · GitHub :wink:

Perfect!
Thanks a lot!
:grinning:

1 Like

Hi @bwaidelich,

that did it for me as well.

Any hint how I would have to create the query if I would have to sort the nodes by a property first and then get the prev() or next()?

3 YEARS LATER

:astonished:

You should be able to chain those operations as usual. did you try:

${q(node).sort('someProp', 'ASC').next().get(0)}

?

Interesting idea. But that didn’t help. I need something like this:

${q(site).find("[instanceof document:News]").sort('date', 'DESC').???( ... now locate the current q(node) in this result ...).next().get(0)

But I just can’t figure out how to position my pointer on the correct node. Any idea?

Again 3 Years later. :melting_face:

Did you find a solution for this? I have the same Problem but couldn’t find a way to get the next on a sorted collection.

The only way i see is to get the whole collection and work with an eel helper on this. But it looks so ugly to me to load all nodes and than pick just two of them. :-/

Can you please start a new thread and describe your use case?

Feel free to mention this topic, but highjacking other threads can lead to confusion and useless notification mails :slight_smile:

1 Like