[opencms-dev] Trying to include a file and have template applied

M Butcher mbutcher at grcomputing.net
Mon Nov 10 21:38:02 CET 2003


Polizzi, Jim wrote:

>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.
>  
>
This would be a regular template, right. I mean, this is what a template 
usually does.

>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.
>  
>
And again, this is pretty easy to do in the template. See if the file 
exists. If yes, then include it.

>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.
>  
>
Now this is where I'm starting to get hazy. Why have a template defined 
for what equates to a snippet of code? Wouldn't you just put the 
"template" inside of the page template you spoke of above? I mean, if 
it's just a table, it would be better and faster to just use the main 
template to do the formatting.

The exception to this would be if you wanted to do many different 
formats for the SideArea file (e.g. 6 or 7 different complex table 
layouts depending on what info is inside the SideArea.html file). In 
that case, you would have to basically create a recursive template 
parser/processor, as others have already suggested.

>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.
>  
>
I don't particularly see a problem with multiple additions. Your 
template may get bigger, but that is still preferable to implementing 
recursive template processing (for performance _and_ complexity reasons)

>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.
>  
>
Again, I think this solution is the more complex way of solving the problem.

In the past, I've done the type of include that I'm explaining as a way 
of providing HTML ads, as well as dynamic or static content ("tip of the 
day" or extra bits of text). It works fairly well, and isn't hard to do.

Others have done something slightly different: they have enabled the 
multiple content bodies option and used the extra body fields to add the 
additional text. For more on that, you may want to search through the 
list archives or check out the forums.

Matt




More information about the opencms-dev mailing list