Automatic next-previous links
Using just a modified page template, it's easy to add automatic next/previous links on a page. You can use this for easy multi-page documents. This is an implementation based on the RichDocument product, but can be adapted.
The basic idea:
You have a long document, which should really be split up into multiple pages to make it easier to read. You also want automatic links to the "next" and "previous" page.
Some pages should include pictures and/or attachments.
Note: this is not a full-scale "Book" or "Publication" with sub-chapters, annotations, bells and whistles. If you need that functionality, look at ATBackTalk. But it's a relatively simple way to publish longer documents in a reader-friendly way.
What is needed:
Almost everything is already included in Plone2.1. To make it easy to include pictures and/or attachments, you'll also need the RichDocument product.
The ordering of the individual pages/chapters will be determined by their container: an Ordered Folder (a regular ATFolder from Plone2.1 is enough).
So, in order to create a multi-page document, or a simple "book", you create a Folder. In this you create the individual pages as RichDocuments. You then set the view on each of these documents to "chapter_view" (which we'll soon create). Order them using the normal "content" view of the Folder. That's it!
Of course you could embellish this by making also a nice view for the container folder. Then again, if you're lazy like me the default folder_listing should suffice...
Steps required:
We're going to add an extra view to the RichDocument. For experiments, you can just create a copy of the "richdocument_view" page template in the "Custom" skin folder and call it "chapter_view". Also make sure to list this as one of the "available view methods" for RichDocument in portal_types.
When you're satisfied with the results, you should create this chapter_view.pt on the filesystem in the skins folder of (your customised copy of) RichDocument. This product is well-documented, you should easily be able to see how you can register your new view on install.
At the top of "chapter_view", you'll find the following code: :
<metal:main fill-slot="main">
<tal:main-macro metal:define-macro="main"
tal:define="text python: here.CookedBody(stx_level=2)">
We need to add some extra lines, to make it look like this: :
<metal:main fill-slot="main">
<tal:main-macro metal:define-macro="main"
tal:define="text python: here.CookedBody(stx_level=2);
chapters python:here.aq_parent.getFolderContents(contentFilter = {'portal_type' : ['RichDocument']});
sibl python:[p for p in chapters];
num_sibl python:len(sibl);
pos python: [i for i in range(num_sibl) if sibl[i].getId == here.getId()][0];">
Now we're almost done! All you need to do is to insert a link section somewhere at the bottom of the page template: :
<div class="listingBar" tal:condition="python: next or prev"
tal:define="next python:pos < num_sibl-1;
prev python:pos != 0;">
<span tal:condition="next">
<a class="listingNext"
tal:define="nextsib python:sibl[pos+1]"
tal:attributes="href nextsib/getURL"
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 prevsib/getURL"
tabindex="2"
href="">
<span i18n:translate="label_previous">
Previous: </span>
<span tal:replace="prevsib/Title" />
</a>
</span>
</div>
Of course you can put other statements in the page template, to give more information about the multi-page document to your readers. The following snippet will say something like "Page 2 of 15": :
<div>
<span i18n:translate="Page">
Page </span>
<span tal:replace="python:pos+1">5</span>
<span i18n:translate="event_from">
of </span>
<span tal:replace="python:num_sibl">10</span>.
</div>
And a form, allowing quick jumps to all pages: :
<form method="get" action="redirect_to" style="text-align:right; float: left;">
<label for="dest" class="hiddenStructure">Jump to:</label>
<select name="dest"
tabindex="3">
<option tal:repeat="s sibl"
tal:attributes="value s/getId;
selected python:test (s.getId == here.getId (),
'selected', None);">
<tal:page content="s/Title">Some Page</tal:page>
</option>
</select>
<input class="standalone"
type="submit"
value="Go"
i18n:attributes="value"
tabindex="4" />
</form>
For the form to work, you'll also need to create a custom Python script called redirect_to.py: :
## Script (Python) "redirect_to"
##title=Simple Redirection
##parameters=dest
if dest.startswith('http://'):
return context.REQUEST.RESPONSE.redirect(dest)
else:
return context.REQUEST.RESPONSE.redirect('%s/%s' % (context.aq_parent.absolute_url(), dest))
Thank you: snippets of this howto were lifted out of the PloneHelpCenter code. And a big thank you to optilude for creating RichDocument.
