Extension, Module

Archived
Forum
(read-only)

Stash

ExpressionEngine 2, ExpressionEngine 3, ExpressionEngine 4, ExpressionEngine 5, ExpressionEngine 6

Back to this add-on's main page
View Other Add-ons From Mark Croxton

     

Next Prev Functionality for lists

Feature Request

Sanity11
Sanity11

Hi Max,

I am working with Stash for a new project for the first time, and it’s really awesome. What would be great if there was some way to get next / prev functionality working with with lists. Right now I have made a custom plugin to get this working, wich is fine. But it might be cool to have it in Stash!

My plugin works as follows:

I have to make sure I have a key “url_title” in my list. And then pass in the url title of the currently displayed item from the list that is matched against the url title aswel. (displaying only one entry of the list).

Then my plugin can work:

{exp:webs_stash:prev name="superlist" match="{segment_3}"}
  
<a href="/{url_title}">PREV{title}</a>
 
{/exp:webs_stash:prev}

 {exp
:webs_stash:next name="superlist" match="{segment_3}"}
  
<a href="/{url_title}">NEXT{title}</a>
 
{/exp:webs_stash:next} 

Something like that maybe?

EDIT: Of course you can have it if you think it’s of any use. Right now it’s limited to just the needs we have for our project.

Mark Croxton
# 1
Developer
Mark Croxton

Could you not use pagination {previous_page} and {next_page} tag pairs?

https://github.com/croxton/Stash/wiki/{exp:stash:get_list}#pagination—prefix

EDIT: nevermind, I see you mean when you just have one matched item. OK, FR noted.

Sanity11
# 2
Sanity11

Hi Max,

Yes, pagination won’t really work for what I’m after. There are a couple of reasons:
- I need data like a title and maybe an image for the next or previous page.
- The url like this is very clean. It just contains the url title of the currently displayed entry.
- I can easily loop through the results infinitely if I want. When you click next on the last result it will go to the first result.

Cool that it’s noted :).

Texcam Admin
# 3
Texcam Admin

Mark, did you ever add this type of functionality into Stash?  I’ve run into the same issue where I have a single entry view with a next/previous requiring specific parameters not provided via pagination.

Mark Croxton
# 4
Developer
Mark Croxton

It’s been a while but here’s an idea… you could capture the {absolute_count} of the list item, and then use another stash:get_list and pass the absolute_count to the offset=”{absolute_count}” parameter, with limit=“1” to get the next item in the list. You would need to do absolute_count -1 for the previous list item, so might need a math plugin for that.

Does that make sense?

Texcam Admin
# 5
Texcam Admin

I think I dreamed of some variation of that last night.  Makes total sense.  I’ll try it.  Thanks, Mark.

Texcam Admin
# 6
Texcam Admin

If I capture the ‘absolute_count’ in one get_list, how do I pass that value to another get_list.  I’ve tried many combinations and it doesn’t seem to permit it.

Mark Croxton
# 7
Developer
Mark Croxton

Using a nested list would be easiest.

{exp:stash:get_list name="my_list" limit="1"}

 
    {
!-- next item in the list --}
    {exp
:stash:get_list:nested name="my_list" prefix="nested" offset="{absolute_count}" limit="1"}
        {nested
:url_title}
    {
/exp:stash:get_list:nested}

{
/exp:stash:get_list} 
Texcam Admin
# 8
Texcam Admin

Yes, the nested worked.  Amazing add-on you have there.  Never ceases to amaze me how many build issues it magically solves.  Thanks again, Mark.