We can generate an index page from the content stored in our wiki. This provides an alternative navigation, and a summary of the site.
We envisage the index being reachable from the root site menu. We can add support at a later time for reaching the index regardless of which article is being read.
Source files here are indexpage.py, indexcontent.pt and indexof.pt
The index page should show the site layout, including masthead, navigation and footer, so we start by defining a model IndexPage
.
The Content
section for an ILayout
is rendered through a viewlet, and we define a viewlet called IndexContent
for this purpose:
The namespace() method makes a template variable called site available within the template, and the definition in indexcontent.pt refers to this variable:
This fills the sectionItems
container with list items from an indexof
view on the site.
The IndexOf
view produces a list item for each contained IArticle
, and each of those list items may have a <ul>
container containing sub items. These sub items are rendered using a recursive call to IndexOf
.
The view/articleNumber
method above depends on the fact that to reach a given node in the hierarchy, one would already have had to visit each parent along the way. So the new article number becomes the parents article number with the current nodes order appended. That number is then stored temporarily with the node for use by any children.
The sortedItems()
method uses the IArticleSorted
interface discussed prevously to produce an ordered list of articles.
To produce the index page given the ISiteRoot
, we define a view called indexpage. This creates an IndexPage()
instance, and uses view = component.getMultiAdapter((page, request), name='index')
to instantiate the ILayout
view. We then simply call the view to produce the site index, and return the HTML.
The location.located()
method above sets the __parent__
and __name__
attributes for the page, which is necessary for view.url()
to produce a valid url.
To add the index to the menu for all pages other than just the first, we have only a few changes. The IndexButton definition changes to use a context of IArticle
rather than ISiteRoot
, and we alter PageView
as follows: