[opencms-dev] include html files from templates

Jonathan Woods jonathan.woods at scintillance.com
Wed Oct 4 12:14:23 CEST 2006


This is how I do something like what you're asking about.  Lots of steps, so
bear with me while I explain....
 
Create [my-page] as 'New / Page with free text'.  In the dialogue which
appears, choose as the new file's template a JSP file which you've already
created and placed in your module's 'templates' folder.  This JSP file is
what OpenCms will execute when the URL for [my-page] is invoked.  You can
populate the starting content of [my-page] by choosing a file in the 'Copy
body from' drop down; the files which appear there are taken from your
module's default_bodies folder.
 
As for the JSP, you want it to do what you've outlined: contain some code
(may included from a JSP snippet elsewhere) which renders menus, and also
bring in the content from [my-page].  Here's some JSP code which does just
that for me:
 
<%@ page pageEncoding="UTF-8" session="false" import="all your imports here"
%>
<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %>


<cms:include file="../elements/pagecontentopen.jsp"/>

<div class="freeformContent"><cms:include element="body"/></div>

<cms:include file="../elements/pagecontentclose.jsp" />

The included JSP paths are relative to the path of the JSP in which this
code appears, so you'll need an elements directory in your module which
contains the cited resources.  In my case, these JSPs top and tail page
content; the top (pagecontentopen.jsp) renders the HTML preamble and page
header and top/left navigation; the tail (pagecontentclose.jsp) renders the
page footer and HTML closure.  The <cms:include> tag in the middle is
confusingly similar, but in this case the code means 'include the XML
element named 'body' from the file referred to by the URL which caused me
[this JSP] to be invoked'.
 
I've mentioned modules a few times.  To create a module of your own, create
a folder named <your module name> in /system/modules, and create JSPs etc in
folders underneath that.
 
Jon
 
  _____  

From: opencms-dev-bounces at opencms.org
[mailto:opencms-dev-bounces at opencms.org] On Behalf Of Felix Sprick
Sent: 04 October 2006 10:27
To: opencms-dev at opencms.org
Subject: [opencms-dev] include html files from templates



Hi all,

 

I have a question concerning includes in templates. What I like to do: I
want to have a "navigation panel" that consists of several blocks with
images and text (basically HTML blocks). I want this panel included in every
of my pages, that's why I would like the entire panel from my template on
which the pages are built. My question: how do I include the blocks (HTML
pages that can be edited with WYSIWYG editor) from /sites/default/[my-page]
inside my template?? Everything I tried ended up in a file not found
exception.

 

Does anyone know if that's possible or know how to do it?

 

Your help is highly appreciated!

Felix 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20061004/e4183107/attachment.htm>


More information about the opencms-dev mailing list