[opencms-dev] How to build a template (Re: Manifest Manual)
Claus Priisholm
cpr at codedroids.com
Sun Apr 16 11:08:32 CEST 2006
Well, fiddling with manifests is not what I think of as a newbie
thing... If all you need is to build a template that you can use for
your pages it is not that complicated (though building templates can be
one of the major efforts as the requirements for a site can make them
quite complicated - templateone is such an example):
1. Go to the administration view, select Modules Management. Create a
new module. Fill in the values, most important is the Package name, for
this example: "my.module.name" (typically you would use a java package
inspired naming strategy). The rest you can fill in as you see fit (or
leave them blank), but do check all the suggested folders so it will
create the necessary file structure for you.
2. Switch to the explorer view and the "/" site. Go to
/system/modules/my.module.name. There you have the file structure for
the module. Go into the "templates" folder and create a new JSP - e.g
"mytemplate.jsp". Set the Title-property to something useful, e.g. "My
template", as it is the title you will see when you select a template
later on when creating new pages for the site.
3. Enter the code, I've included a simple example. But despite its
simplicity it shows most of the basic steps:
<%@page buffer="none" session="false" import="org.opencms.file.*,
org.opencms.jsp.*, java.util.*, org.opencms.util.*" %>
<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %>
<%
CmsJspActionElement cms = new CmsJspActionElement(pageContext, request,
response);
if (cms.template("HEADER")) {
%>
<html>
<head>
<title><%= cms.property("Title", "uri", "Just some default title...")
%></title>
<cms:editable />
</head>
<body>
<table border="1">
<tr>
<td width="30%" valign="top">
<cms:include page="../elements/navigation.jsp" />
</td>
<td width="70%" valign="top">
<%
}
if (cms.template("CONTENTS")) {
%>
<cms:template ifexists="body">
<cms:include element="body" editable="true" />
</cms:template>
<%
}
if (cms.template("FOOTER")) {
%>
</td>
</tr>
</table>
</body>
</html>
<%
}
%>
I prefer using scriplet code over taglibs, but that is just a personal
preference (a dislike towards having to learn yet another syntax...) But
actually you'll probably end up mixing them as you see fit...
The cms.template("XX") statements are not really necessary unless you
plan using this template as a master for other similar templates
(typically because you want to replace the CONTENTS part with some
specific code rather than the text entered by the end user).
But other than that it is probably the simplest template you can get
away with: It includes the title-property of the page it is used on as
the window title. It includes a jsp script to build the navigation and
finally it includes the body-element from the page. Also it enables the
direct edit function (optional).
4. Just to make it fully functional, here's the navigation.jsp (put in
the elements-folder). This is actually code to build a sitemap - you'll
probably end up using the getNavigationXXX stuff differently to suit
your needs for the navigation:
<%@page buffer="none" session="false" import="java.util.*,
org.opencms.file.*, org.opencms.jsp.*, org.opencms.util.*" %>
<%!
public void buildSiteMap(CmsJspActionElement cms, String uri,
java.io.Writer out) throws Exception
{
List navList = cms.getNavigation().getNavigationForFolder(uri);
if (navList.size() > 0) {
out.write("<ul>\n");
Iterator navItem = navList.iterator();
CmsJspNavElement nav;
while (navItem.hasNext()) {
nav = (CmsJspNavElement) navItem.next();
String navText = nav.getNavText();
String navPath = nav.getResourceName();
if (nav.isFolderLink()) {
out.write("<li><a href=\"" + navPath + "\"><b>" + navText +
"</b></a></li>\n");
buildSiteMap(cms, navPath, out); // recurse...
} else {
out.write("<li><a href=\"" + navPath + "\">" + navText +
"</a></li>\n");
}
}
out.write("</ul>\n");
}
}
%>
<%
CmsJspActionElement cms = new CmsJspActionElement(pageContext, request,
response);
buildSiteMap(cms, "/", out);
%>
5. Switch to the "/sites/default/" site and create a new page - you can
now select "My template" as the template for the page. And then you're
ready to rock...
regards
Claus
Holger Schick wrote:
> Hello,
> well i did my first template. overall i took me hours - but only to find errors like editing the following attributes wrong.
> I used a wrong order= and id= attribute value. I couldn't find a documentation where i can find id- and order numbers which i can use.
>
> <newresource page="structurecontent" uri="newresource_xmlcontent.jsp?newresourcetype=seminar" order="777"/>
> <type class="org.opencms.file.types.CmsResourceTypeXmlContent" name="seminar" id="79">
>
> Another Error was because of all the copy and paste a pasted a already used uuid. The Exception was not while importing an invalid id or something. I retreived a marshalling exception because the module used the wrong xsd. I found the reason in the import module protocol. There was a file name which i didn't wanted to import.
>
> What are your experiences with open cms? Are this typical newbies errors or do you have also such errors even if you are working already with open cms?
> Or is the only reason that i couldn't find a good documentation and somewhere is one?
> Is there anywhere more documentation available for the manifest.xml or really good community web sites?
> Is there also a build tool for the manifest available something like a ant script?
>
>
> thanks
>
> Holger
> _______________________________________________________________
> SMS schreiben mit WEB.DE FreeMail - einfach, schnell und
> kostenguenstig. Jetzt gleich testen! http://f.web.de/?mc=021192
>
>
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/mailman/listinfo/opencms-dev
>
--
Claus Priisholm, CodeDroids ApS
Phone: +45 48 22 46 46
cpr (you know what) codedroids.com - http://www.codedroids.com
cpr (you know what) interlet.dk - http://www.interlet.dk
--
Javadocs and other OpenCms stuff:
http://www.codedroids.com/community/opencms
More information about the opencms-dev
mailing list