ztm.navigator is essentially two viewlet managers representing each their column that select viewlets based on what you are viewing. You can find more information about viewlets in the zope.viewlet module.
Please read the documentation for zope.viewlet.
Viewlets usually show the state some property of the object you are viewing, like the subject identifiers of a topic. The viewlet should only be shown if there are any properties or some other condition is met. In the example of subject identifiers, the viewlet only returns markup if there are any identifiers.
A viewlet is a simple Python class that provides an HTML-fragment. Viewlets are found through the component architecture which means that other packages can embed their own blocks.
An example of such a block is the one inserted by ztm.editor which provides links to the editor and a button to create a reifier for the topic map itself. (The reifier is used to add metadata and other descriptions of the topic map itself.)
A viewlet is a class implemented something like this:
import zope.viewlet.viewlet
class MyViewlet(zope.viewlet.viewlet.ViewletBase):
"""My viewlet."""
order = 0
def render(self):
return 'hello world from my viewlet'
Note
You do not actually have to subclass ViewletBase. It is enough to declare that your class implements IViewlet and provide implementations for the three methods __init__(self, context, request, view, manager), update(self) and render(self).
The order attribute simply lets the viewlet manager know how to sort the viewlets. Increase the number to move down the column.
You must now register the viewlet. This can be done with ZCML like this:
1 2 3 4 5 6 7 8 9 10 | <include package="zope.contentprovider"/>
<include package="zope.viewlet"/>
<browser:viewlet
zcml:condition="installed ztm.navigator"
for="ztm.topicmaps.interfaces.ITopicMap"
name="ztm.editor.editlink"
class="ztm.editor.browser.navigator_viewlets.TopicMapEditLink"
manager="ztm.navigator.browser.interfaces.ILeftColumn"
permission="zope.View"
/>
|
Line 1 and 2 loads zope.viewlet and zope.contentprovider (a dependency of zope.viewlet that it for some reason does not itself).
Line 4 means that the viewlet is only registered when ztm.navigator is installed and loaded.
Line 5 is the kind of object you wish to register you view for. ITopicMap for topicmap and scope objects. ITopic for regular topics.
Line 6 is just a name.
Line 7 is the dotted path to the Viewlet you defined above.
Line 8 is the manager to use. You have two choices: ztm.navigator.browser.interfaces.ILeftColumn for left column and ztm.navigator.browser.interfaces.IRightColumn for the right column.
Line 9 is the permission required of the principal to view the viewlet.
In order to look visually integrated the markup your viewlet returns must use the class names described below:
<div class="ztmNavBox" id="yourid">
<div class="head"><h2>Title</h2></div>
<div class="body">
<div class="helpPanel">Helptext goes here.</div>
</div>
</div>
We usually create a skin folder inside the browser folder and put all markup there.
If you would like to use a page template please try something like this:
import zope.pagetemplate.pagetemplatefile
class MyViewlet(zope.viewlet.viewlet.ViewletBase):
"""My viewlet rendered by a template."""
template = zope.pagetemplate.pagetemplatefile.PageTemplateFile('skin/mine.pt')
def render(self):
# The input here can be accessed from the `options` attribute.
return self.template(
viewlet=self,
view=self.view
request=self.request)
Special scripts are not supported in this version. You will have to embed them in your markup or customize the layout template.
Special styles are not supported in this version. You will have to embed them in your markup or customize the layout template.
You can override viewlets using standard ZCML (Zope Configuration Markup Language)/ZCA Zope Component Architecture).
Translations are done through the framework provided by zope.i18n if you use a page templates to render the markup. Translations are stored in your own package.
You should probably check out the [i18n] section in ztm.navigators buildout.cfg for an example of how to set this up.