SV: [opencms-dev] include html files from templates
Felix Sprick
felix.sprick at netlight.se
Wed Oct 4 16:39:35 CEST 2006
Hi,
I have found a way now. This is the template file:
<%@ page session="false"
import="java.util.Iterator,
java.util.List,
org.opencms.jsp.CmsJspNavBuilder,
org.opencms.jsp.CmsJspNavElement,
org.opencms.jsp.CmsJspActionElement"%>
<%@ taglib prefix="cms"
uri="http://www.opencms.org/taglib/cms" %>
<cms:template element="head">
<!DOCTYPE html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title><cms:property name="Title" escapeHtml="true"/></title>
</head>
</cms:template>
<body>
<!-- main page -->
<cms:template element="body">
<cms:include element="main" editable="true"/>
</cms:template>
<!-- navigation include-->
<%
CmsJspActionElement cms =
new CmsJspActionElement( pageContext, request, response );
java.util.Locale locale = java.util.Locale.ENGLISH;
String content1 =
cms.getContent("/mysite/leftNavigation.html","block1",locale);
//cms.include(content1); //does not work
out.println(content1);
String content2 =
cms.getContent("/mysite/leftNavigation.html","block2",locale);
out.println(content2);
%>
</body>
</html>
It includes leftNavigation.html into the pages that are built with this
template. The include tag did not work (still the file not found
exceptions), but I could do the same with cms.getContent and then print it
out to the site.
Thanks for your help, Jon, I really appreciate it.
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 16:02
Till: 'The OpenCms mailing list'
Ämne: RE: [opencms-dev] include html files from templates
Felix -
I think I'm losing track here. In my version - which of course isn't the
only way of doing things - my HTML file contains only data; the JSP file in
<module root>/templates is the whole of the 'view' implementation, so it's
the JSP which does the <include>ing (of content). The HTML doesn't contain
any <includes> or references to template elements, and in fact it doesn't
'know' anything about the template which will render it. The editors edit
the HTML file, and the view (JSP) renders the result.
Jon
_____
From: opencms-dev-bounces at opencms.org
[mailto:opencms-dev-bounces at opencms.org] On Behalf Of Felix Sprick
Sent: 04 October 2006 13:26
To: 'The OpenCms mailing list'
Subject: SV: [opencms-dev] include html files from templates
Hey Jon,
Thanks again for the quick reply. Its still not 100% clear to me how this
solves my problem.
1. I create a module, lets call it myModule
2. I create a myTemplate.jsp at myModule/templates which has a body
that can be edited by editors and which includes the navigation.html.
Something like this:
<%@ page session="false" %>
<%@ taglib prefix="cms"
uri="http://www.opencms.org/taglib/cms" %>
<cms:template element="head1">
<!DOCTYPE html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title><cms:property name="Title" escapeHtml="true"/></title>
</head>
</cms:template>
<body>
<!-- main page -->
<cms:template element="body">
<cms:include element="body" editable="true"/>
</cms:template>
<!-- navigation. Includes html file which is located at sites/default,
accessible for editors -->
<cms:include file="/sites/default/mySite/navigation.html" />
</body>
</html>
3. I create a new HTML file at location
/sites/default/mySite/myMainSite.html which uses myTemplate. Editors of this
file can edit the body part of this file. The navigation, however, should
always be included from ="/sites/default/mySite/navigation.html.
4. Create Navigation.html with empty layout template. Editors can
edit the navigation in the sites/default view with an HTML editor.
5. I receive a file not found exception for navigation.html, also
<cms:include file="/mySite/navigation.html" /> or <cms:include
file="http://localhost:8080/opencms/opencms/mySite/navigation.html" /> do
not work.
Thanks,
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 13:26
Till: 'The OpenCms mailing list'
Ämne: RE: [opencms-dev] include html files from templates
Sorry - I didn't read your question properly!
If you set up a file in <module root>/default_bodies and put something like
this in it:
<?xml version="1.0" encoding="UTF-8"?>
<pages xmlns:xsi=" <http://www.w3.org/2001/XMLSchema-instance>
http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="
<http://www.opencms.org/dtd/6.0/xmlpage.xsd>
http://www.opencms.org/dtd/6.0/xmlpage.xsd">
<page language="en">
<element name="block1">
<links/>
<content><![CDATA[content for nav block 1]]></content>
</element>
<element name="block2">
<links/>
<content><![CDATA[Content for nav block 2]]></content>
</element>
<element name="block3">
<links/>
<content><![CDATA[Content for nav block 3]]></content>
</element>
</page>
</pages>
then the file would be HTML-editable - FCKEditor renders a drop-down which
allows you to choose the element you're editing - and your JSP could include
elements by naming them. Problem with this is that number of blocks is
fixed, but maybe that would be OK for you.
Jon
_____
From: opencms-dev-bounces at opencms.org
[mailto:opencms-dev-bounces at opencms.org] On Behalf Of Felix Sprick
Sent: 04 October 2006 12:15
To: 'The OpenCms mailing list'
Subject: SV: [opencms-dev] include html files from templates
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
havent 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 couldnt 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, thats 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 thats 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/f3887248/attachment.htm>
More information about the opencms-dev
mailing list