[opencms-dev] Trying to include a file and have template applied
Polizzi, Jim
Jim.Polizzi at bankofamerica.com
Mon Nov 10 21:03:01 CET 2003
Wow!!!
Thanks for taking so much time in answering my question...
Actually - I was trying to simplify my question so that I could give a good code sample. In reality - I'm to create it so that my users (content editors) don't write ANY JSP's... but I left out some stuff in my original description.
Here's what I'm really trying to do (with NO code samples).
I want to have an overall Page level template (Page.jsp template) (which applies headers, footers, nav menus, etc.). Then, allow the user to specify whatever body content that they like.
Then, I'd also like my Page level template to look for (for example) a file in the same directory as the current page called "SideArea.html" (or whatever). If it finds it - it includes it - otherwise, it doesn't.
The SideArea.html file has a template defined for it (the SideArea.jsp template) which has a table setup to make a nice "feature box". The user enters their content into this SideArea.html file - and I want the SideArea.jsp template applied to it.
I can imagine several of these types of elements (SideArea / Feature Area / etc.)... that will be included in the page if they exist... the main point being that I want to provide Templates for each of these Page Sub-Elements - to simplify the work that the User (content editor) has to do to compose a rich page - that is consistant across the site.
In order to do this - I need a way to include a file from my Main Page Template (Page.jsp) - and the included file needs to have IT'S template applied.
Is there NO WAY to do this?
Again - thanks for your help.
Jim Polizzi
-----Original Message-----
From: M Butcher [mailto:mbutcher at grcomputing.net]
Sent: Monday, November 10, 2003 2:32 PM
To: opencms-dev at opencms.org
Subject: Re: [opencms-dev] Trying to include a file and have template
applied
Jim,
How are you including the template? Does the _content_ reference the
template or does the _jsp_ reference the template.
If the _content_ (the body) references the template, then you will not
see the template get rendered at all, because cms.include doesn't apply
templates, it just includes the body.
If the _jsp_ references the template, then the output you get ought to be:
<h2>This is from the template!!!</h2>
<html>
<head>
<title>Test Page</title>
</head>
<body leftMargin="0" topMargin="0" marginheight="0" marginwidth="0">
<h1>This is myJSP.jsp</h1>
<h1>including myPage.html.</h1>
<h3>This is the body content</h3>
</body>
</html>
Note that the heading is printed before the <html> tag because the
template gets applied before the JSP is written out. In browsers that
auto-repair HTML, the header may get dropped off, since it is overtly
illegal HTML.
If I might suggest something, I think you are approaching the problem
the wrong way. The template should have the layout information, the JSP
should have the logic, and the page should have content. I would suggest
structuring things this way:
The template should include the JSP _and_ the content, OR the template
should render the JSP, which then includes the content. All of the main
layout info (<html><head/><body/></html>) should be in the template, not
the JSP.
So, in the JSP's properties, it should reference the template. If the
JSP is going to include the content of myPage, then it doesn't matter
what the template of myPage is set to, as it will be ignored by the JSP
anyway.
This way, the output will be constructed like this:
render template -> include JSP -> include content
Hope I didn't misunderstand you. :)
Matt
Polizzi, Jim wrote:
> Let me restate the problem - with much more definition.
>
> I'm writing a jsp page and trying to include a file (.html - or
> whatever) that has a template defined for it (thus allow the user to
> create a body - but I define the formatting, etc.). I call
> "cms.include("myPage.html");". The results that I get are the BODY of
> the included file but not the Template stuff (my formatting stuff -
> tables, etc.)
>
> I've created a very simple example (below) that shows exactly what I mean.
>
>
> Let's say that I have the following template: (myTemplate.jsp)
>
> <%@ page session="false"
> import="com.opencms.flex.jsp.*"
> import="com.opencms.flex.util.CmsMessages"
> import="com.opencms.file.*"
> import="java.lang.*"
> import="java.util.*"
> %>
> <%
>
> // initialise Cms Action Element
> CmsJspActionElement cms = new CmsJspActionElement(pageContext,
> request, response);
>
> out.println("<h2>This is from the template!!!</h2>");
>
> cms.include(null, "body");
>
> Also - let's say that you have a page (myPage.html) that uses
> myTemplate.jsp - with the following body content:
>
> <h3>This is the body content</h3>
>
> Good - now - let's say that we have the following JSP file - (myJSP.jsp):
>
> <%@ page session="false"
> import="com.opencms.flex.jsp.*"
> import="com.opencms.flex.util.CmsMessages"
> import="com.opencms.file.*"
> import="java.lang.*"
> import="java.util.*"
> %>
> <%
> // initialise Cms Action Element
> CmsJspActionElement cms = new CmsJspActionElement(pageContext,
> request, response);
> %>
>
> <html>
> <head>
> <title>Test Page</title>
> </head>
> <body leftMargin="0" topMargin="0" marginheight="0" marginwidth="0">
> <h1>This is myJSP.jsp</h1>
>
> <%
> out.println("<h1>including myPage.html.</h1>");
> cms.include("myPage.html");
> %>
>
> </body>
> </html>
>
> Ok - that's all of the files in this example. When I open myJSP.jsp,
> the results are:
>
> <html>
> <head>
> <title>Test Page</title>
> </head>
> <body leftMargin="0" topMargin="0" marginheight="0" marginwidth="0">
> <h1>This is myJSP.jsp</h1>
>
> <h1>including myPage.html.</h1>
> <h3>This is the body content</h3>
>
> </body>
> </html>
>
>
> NOTE: I DON'T get the Template output --> <h2>This is from the
> template!!!</h2>
> I don't understand why not - or how I CAN get it.
>
> Any help in this would be appreciated.
>
> Jim Polizzi
>
> -----Original Message-----
> *From:* Claus Priisholm [mailto:cpr at codedroids.com]
> *Sent:* Monday, November 10, 2003 5:57 AM
> *To:* opencms-dev at opencms.org
> *Subject:* Re: [opencms-dev] Trying to include a file and have
> template applied
>
> I'm not sure what kind of include you're using (and what it is
> that you need the template to do), but I had a problem where an
> include of a header 'page' would mess up the remaining includes on
> the page. In order for that to work I would either have to use a
> Java URLConnection to actually fetch the result or apply this
> workaround provided by Brett Beaumont:
>
> http://mail.opencms.org/pipermail/opencms-dev/2003q3/007010.html
>
> On fredag, nov 7, 2003, at 17:00 Europe/Copenhagen, Polizzi, Jim
> wrote:
>
> I am trying to include a file (.html) that has a template
> defined for it. The problem is that the file is included -
> but the template is not applied... I'm ONLY getting the body
> content - without the template
> Can anyone shed some light on this?
>
> --
> Claus Priisholm
> +45 48 22 46 46
> cpr (you-know-what) interlet.dk - cpr (you-know-what) codedroids.com
> http://www.interlet.dk - http://www.codedroids.com
>
_______________________________________________
This mail is send to you from the opencms-dev mailing list
To change your list options, or to unsubscribe from the list, please visit
http://mail.opencms.org/mailman/listinfo/opencms-dev
More information about the opencms-dev
mailing list