[opencms-dev] Properties template and template-elements

Paul-Inge Flakstad flakstad at npolar.no
Mon Mar 29 16:41:20 CEST 2010


Tim,

xmlpage is not a type of structured content, it is an individual resource type in OpenCms, separate from xmlcontent. I'm quite certain of this. As for the rest I'm about to explain, I'm not absolutely sure, but I'll at least explain the idea I'm working from, with some code examples included. (I'm using xmlpage as an example only because it's the only resource type I know of wherer OpenCms makes use of the "template" property.)

xmlpage files do not _need_ to have their "template-elements" property set, only their "template" property is required. OpenCms will use the JSP defined as "template" for rendering the page.

xmlcontent files do not _need_ to have their "template" property set, only their "template-elements" property is required. OpenCms will use the JSP defined as "template-elements" for rendering the page.

However, I think it's a good idea to utilize the "template" property for xmlcontent as well, because this allows for the usage of one single "master template", reducing duplicate code. But you have to make use of the "template" property yourself, OpenCms will not do this for you. So, in the xmlcontent's "template-elements" JSP, you'll have to manually read the "template" property and include the neccessary elements.



Typically, my master template ("template" property) looks kinda like this:

<cms:template element="header">
   <!DOCTYPE ....>
   <html ...>
   <head>....</head> <!-- stylesheets, javascripts and so on, common for entire site -->
   <body>
   <div id="header">....<cms:include file="../elements/searchbox.jsp"/>...</div> <!-- header with searchbox, common for entire site -->
   <cms:include file="../elements/navi.jsp" /> <!-- global navigation, common for entire site -->
   <h1><cms:property name="Title"/></h1>
</cms:template>

<cms:template element="contentbody">
   <cms:include element="body" /><!-- this is where content from "body" elements of xmlpage files will be rendered -->
</cms:template>

<cms:template element="footer">
   <div class="footer">...<cms:include file="../resources/footertext.txt" />...</div> <!-- footer content, common for entire site -->
   </body>
   </html>
</cms:template>



and my structured content templates ("template-elements" property) looks kinda like this:

<cms:include property="template" element="header" /> <!-- will include the common top part of the page -->
   <%
   // Handle the specific structured content:
   cms.contentload(...);
   ...and...
   cms.contentshow(...);
   ...and so on....
   // Done handling the specific structured content.
   %>
<cms:include property="template" element="footer" /> <!-- will include the common bottom part of the page -->




I typically set the "master template" on the site root folder, so it's shared across the entire site, for all resource types. And then I set the "template-elements" on specific resource types or folders. For structured content, I often set the "template-elements" property automatically by defining a default property value in opencms-modules.xml.

Hope I was able to shed some light on this, confused as I am myself... :-)

Best regards,
Paul



________________________________
From: opencms-dev-bounces at opencms.org [mailto:opencms-dev-bounces at opencms.org] On Behalf Of Tim Daschner
Sent: 29. mars 2010 15:33
To: The OpenCms mailing list
Subject: Re: [opencms-dev] Properties template and template-elements


Ok thanks for the clarification. So, isn't xmlpage itself a type of structured xmlcontent defined in opencms-modules.XML by some module? If so, then this usage of template property must come from the template used by that module. In other words template is not really used by opencms framework but might be used by a module that alkacon may have written as a part of their distro.  Did I get it right?

Tim

On Mar 29, 2010 8:25 AM, "Paul-Inge Flakstad" <flakstad at npolar.no<mailto:flakstad at npolar.no>> wrote:

Tim,

Just to clearify: for xmlcontent ("Structured content"), the "template" property isn't used by OpenCms. But for other resource types, like xmlpage ("Page with free text"), it is used by OpenCms.

As far as I can tell, the "master template" (the surrounding outer template) works in a slightly different way when working with xmlpage files, compared to working with xmlcontent files:
For xmlpage, the master template has some <cms:include element="..." /> statements that include content from the various element(s) of the xmlpage.
For xmlcontent, the master template is included from the xmlcontent's template, defined in the property "template-elements".

In short, xmlpage files need their "template" property set, xmlcontent files need their "template-elements" property set. If done correctly, you can use the same master template for both.

Best regards,
Paul

________________________________

> From: opencms-dev-bounces at opencms.org<mailto:opencms-dev-bounces at opencms.org> [mailto:opencms-dev-bounces at opencms.org<mailto:opencms-dev-bounces at opencms.org>] On Behalf Of Tim D...

Sent: 29. mars 2010 14:59

> To: The OpenCms mailing list

Subject: Re: [opencms-dev] Properties template and template-elements


> Thank you folks. Yeah, that's how I have used the template elements property so far. I was not awa...


_______________________________________________
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20100329/954a928b/attachment.htm>


More information about the opencms-dev mailing list