-
- 213 Posts
I’ve got a list of articles I’m displaying with Ditto. What I want is to be able to click an article to view the detail, and on that detail page, have a "Prev" and "Next" item so I don’t have to go back to the list of articles. I’ve tried Ditto and the tplCurrentDocument template, but I’m not sure that’s what I need to use. Is there a better snippet for doing this?
-
- 213 Posts
Yes, that’s what I was doing, using pagination, limit=1, and tplcurrentdocument, but never got it completely right. hmmm, that snippet looks promising...i’ll give it a shot.
-
- 1,717 Posts
Thks GaneshXL for this answer.
But as i understand (and tested) this solution requires, inside the document, to recall the ditto call which set up the result id list. Unfortunately, in the document you don’t know how has been set up the list. You could arrive on a document by several different ways with various ditto calls.
Perhaps the solution is to set up the result list of id "somewhere" and then re-use this list of id by the PrevNextDittoList snippet in the document.
Somewhere could be a post parameter or a cookie. What do you think of this idea ?
-
- 956 Posts
I’m not sure I understand. You can make this as flexible as you want. The "glue" is the Ditto id parameter, hence you could use this multiple times per page/template. You could define two prev/next navigation items: e.g. one for books (level 1), another for chapters (level 2). Just use two different id-parameters.
You could place the Ditto call in the document or template in the usual way: [[Ditto? &id=`foo1` &save=`3` ...]]
and then use [!dittoPrevNext? &dittoID=`foo1` ...!] somewhere else. It all depends how your site is organized and structured (templates/chunks).
Of course, you could save the id list in a session var. But even so, PHP still needs to define which doc is next, previous, and current on a page-by-page basis.
-
- 1,717 Posts
Ok, i will try to explain where I think are the limits of this solution.
A first ditto call selects the 10 latest books of a shop: [!Ditto &id=`latest` &parents=`15` &paginate=`1` &display=`10` &sortBy=`absDatePub`!]
This first Ditto call provides a first list of book: book1, book2, book3, book4, ...
A second ditto call (an another menu item) selects the 5 best books selected by customers: [!Ditto &id=`best` &parents=`15` &paginate=`1` &display=`5` &sortBy=`absAvis`!]
This second call provides for instance : book2, book4, book8, book12, book21
Whatever the name of id (best ou latest) , you need to know the correct ditto call to get the right result id list when you use &save=`3` on the document.
If you put [!Ditto &id=`latest` &save=`3` &parents=`15` &paginate=`1` &display=`10` &sortBy=`absDatePub`!] on the book#4 and arrives on the document after using the "better" item menu, your Prev/next navigation will be wrong.
Same thing, if you put : [!Ditto &id=`best` &parents=`15` &paginate=`1` &display=`5` &sortBy=`absAvis`!] on the book#4 and arrives on the document after using the "latest" item menu.
When you execute the ditto call to get the document list, you set up the document list. But after choosing a document (read more ... link), when you arrive on the document, you have lost the context of the ditto call and you are on a different page. And you don’t know how you arrive on this page (best or latest ditto list)
So rather to keep and pass the context (to replay the ditto call with the save option, it could be better to save and pass the result id list when the ditto call is executed to set up the list of document.