SV: [opencms-dev] include html files from templates

Felix Sprick felix.sprick at netlight.se
Wed Oct 4 13:15:05 CEST 2006


Hi Jon,

 

Thanks for your email. Your solutions works, I have tried that already
earlier, but I was actually trying to do this a bit different, sorry if I
haven’t described clearly what I would like to do. Let me try it again:

 

I want to have a number of “blocks” in my navigation panel. Each block
thereby is defined in a page which can be edited with the HTML editor. Since
I want editors to edit the content of the blocks, I would like to place
these block.html files in the explorer view /sites/default. These problems
occurred when trying to do that: first of all, I couldn’t include any HTML
files from within the template, only .jsp files worked. Furthermore, these
jsp files have to reside within /system/modules/[my module]/.. , I could not
manage to link from within a template to a file at /sites/default/[my site].


 

With the solution I have (and with the one you have mentioned), editors of
the content of these “blocks” would have to edit in the within
/system/modules/[my module]/.. view and could NOT use the HTML editor, since
the page has to be a jsp. Is that right? Or am I doing a stupid newbie
mistake ( I am quite new to openCMS)?

 

Thanks a lot,

Felix

 

  _____  

Från: opencms-dev-bounces at opencms.org
[mailto:opencms-dev-bounces at opencms.org] För Jonathan Woods
Skickat: den 4 oktober 2006 12:14
Till: 'The OpenCms mailing list'
Ämne: RE: [opencms-dev] include html files from templates

 

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/0a23508a/attachment.htm>


More information about the opencms-dev mailing list