Problem:
being able to navigate through the items of a Plone folder as you browse them.
case-study:
I had several images and other documents all in the same folder. As they landed on a page, I wanted users to be able to navigate to the previous / next image without having to go back to the root folder.
Solution:
- retrieve the objects from the folder
- place them in a list
- get the position of the current object in the list
- calculate the previous and next positions from the current position (-1 and +1, respectively)
- create the links to these objects (remember to add the template at the end of the object’s url if you have a customised view for such object)
Implementation:
<div metal:fill-slot="main">
<div tal:define=".....
chapters python:here.aq_parent.getFolderContents(contentFilter = {'portal_type' : ['BevanLetterImage']});
sibl python:[p for p in chapters];
numsibl python:len(sibl);
pos python: [i for i in range(numsibl)if sibl[i].getId == here.getId()][0]" >
<!--prev next nav-->
<div class="listingBar" tal:condition="python: next or prev"
tal:define="next python:pos < numsibl-1;
prev python:pos != 0;">
<span tal:condition="next">
<a class="listingNext"
tal:define="nextsib python:sibl[pos+1]"
tal:attributes="href string:${nextsib/getURL}/view"
tabindex="1"
href="">
<span i18n:translate="label_next">
Next: </span>
<span tal:replace="nextsib/Title" />
</a>
</span>
<span tal:condition="prev">
<a class="listingPrevious"
tal:define="prevsib python:sibl[pos-1]"
tal:attributes="href string:${prevsib/getURL}/view"
tabindex="2"
href="">
<span i18n:translate="label_previous">
Previous: </span>
<span tal:replace="prevsib/Title" />
</a>
</span>
</div>
<div style="clear:both"></div>
<!--end prev next nav-->