[opencms-dev] How to use a navigation
David Seikel
david.seikel at icemedia.com.au
Fri Jul 11 07:22:01 CEST 2003
Time for another of my quickie howtos. Who ever it was that was
archiving howtos may want to keep this.
Nguyen La Yen Dung wrote:
> But I don't know how to write these templates in XML language.
>
> If you know howto or have any idea to help me solve the below problem,
> please guide me.
Note, this applies to XML templates, it may be completely different for
JSP. Also note, these are generic instructions, they may not apply to
your problem. They may give some clues though.
First you need to define a navigation element or two -
<ELEMENTDEF name="nav">
<CLASS>com.opencms.defaults.CmsXmlNav</CLASS>
<TEMPLATE>../elements/navigation</TEMPLATE>
</ELEMENTDEF>
Next, include <ELEMENT name="nav/> in your frametemplate as usual.
Then write elements/navigation, here is a skeleton to fill out -
<XMLTEMPLATE>
<naventry>
<![CDATA[
]]>
</naventry>
<navcurrent>
<![CDATA[
]]>
</navcurrent>
<TEMPLATE>
<![CDATA[
]]><method name="getNavRoot">2</method><![CDATA[
]]>
</TEMPLATE>
</XMLTEMPLATE>
(Insert HTML as needed in the above.)
<naventry> is used for all navigation links except for the currently
active page, which will use <navcurrent>. The method getNavRoot is one
of the many methods you can use to create navigation menus, which one
you use depends on what you want to do exactly. To create a second
navigation menu, define an element called "nav2" that uses a different
template file and also include it in your frametemplate.
Now for the problems.
OpenCMS's menu code acts differently if it is creating the menu for
index.html, the jury is still out about wether to call this a bug or a
feature. For this reason, we have to be carefull about this. It works
fine for every file except for the index file, where I get different
results depending on wether it is called index.html or index.jsp. Since
I am not using JSP, it doesn't really matter what I call it. To get it
to work as advertised, the index page has to be called index.html in the
leaf nodes, and index.jsp everywhere else. For example with a directory
structure like this -
* project
*
o sub1
o sub2
o
+ sub2_1
+ sub2_2
I need to have these index files for it all to work -
* project/index.jsp
* project/sub1/index.html
* project/sub2/index.jsp
* project/sub2/sub2_1/index.html
* project/sub2/sub2_2/index.html
They all use the same template for the navigation element. While I am
developing this, it is fine as I can keep track of this and change the
names as needed (adding a new folder inside sub2_1 would require a name
change for project/sub2/sub2_1/index.html). But we hand this over to the
client soon, and they may want to add sub folders, and when they do the
navigation will break.
Only the currently active page uses <navcurrent> ALL others use
<naventry>, including the current directory. I got around this by
changing the com.opencms.defaults.CmsXmlNav java class to do the right
thing. Since XML templates are deprecated, I doubt if the authors will
include this. I had previously sent in a patch for some other problem
but received no feedback. What exactly is the proceedure for submitting
patches?
More information about the opencms-dev
mailing list