[opencms-dev] content of called html-page can not be included intemplate

Claus Priisholm cpr at codedroids.com
Thu Aug 19 17:30:02 CEST 2004


Just to make sure, you do have a scenario like this:

/Banner.html (page type, using some template - example text is "BANNER")
/Footer.html (page type, using some template - example text is "BANNER")
/Test.html (page type, using a template similar to the one below - 
example text is "CONTENTS")

Template used by Test.html something along the lines

----8<----
<% CmsJspActionElement cms = ... %>

<% cms.include("/Banner.html"); %>

<% cms.include(null, "body", null); %>

<% cms.include("/Footer.html") %>
----8<---

And you expect to see a page like:

BANNER
CONTENTS
FOOTER

but get this instead:

BANNER
BANNER
FOOTER

Using the supplied hack you can do something like this (note the !, the 
= and the lack of ;)
----8<----
<%! public String include_hack .... %>

<% CmsJspActionElement cms = ... %>

<%= include_hack(cms, "/Banner.html", null, null) %>

<% cms.include(null, "body", null); %>

<%= include_hack(cms, "/Footer.html", null, null) %>
----8<---

That fixes the problem for me, so that the 'body' include works again.


On 18/8-2004, at 15.52, Niina Meronen wrote:

> Thank you Claus for your answer and sample code. Unfortunately I 
> couldn’t get it working. I am able to put the content of the file 
> called any other place on the page, but when adding it to the right 
> place, it is always replaced by the content of previous element. If I 
> set all the other elements but the one that has been called not to be 
> included, the content of called file is shown correctly. It doesn’t 
> make any difference whether I am using method include_hack or 
> cms.include, so maybe I am using the code in a wrong way?!
>
>  
>
> Would it be possible to send an example how you are using that code or 
> something? I am desperate with this problem.
>
>  
>
> BR,
>
> Niina Meronen
>
>   
>
>
> From: opencms-dev-bounces at opencms.org 
> [mailto:opencms-dev-bounces at opencms.org] On Behalf Of Claus Priisholm
> Sent: 18. elokuuta 2004 10:19
> To: The OpenCms mailing list
> Subject: Re: [opencms-dev] content of called html-page can not be 
> included intemplate
>
>   
>
> I don't recall who originally made this contribution, I think you can 
> find it in the 2003 archives. It may have further details on the 
> subject, and furthermore I seem to recall fiddling a bit with the 
> original hack to make it fit my needs, so try to look it up if the 
> solution below doesn't work for you.
>
>  This is what I've used in a couple of situations where I ran into the 
> same problem as you, use it as you would the cms.include() method:
>
>  ----8<----
>  public String include_hack(CmsJspActionElement cms, String uri, 
> String element, Map parameters) throws com.opencms.core.CmsException {
>  CmsXmlTemplate t = new CmsXmlTemplate();
>  CmsXmlTemplateFile tf = new CmsXmlTemplateFile(cms.getCmsObject(), 
> "/system/bodies" + uri);
>  if (parameters != null) {
>  try {
>  HashMap modParameterMap = new HashMap(parameters.size());
>  // ensure parameters are always of type String[] not just String
>  Iterator i = parameters.keySet().iterator();
>  while (i.hasNext()) {
>  String key = (String)i.next();
>  Object value = parameters.get(key);
>  if (value instanceof String[]) {
>  modParameterMap.put(key, value);
>  } else {
>  if (value == null)
>  value = "null";
>  String[] newValue = new String[] { value.toString()};
>  modParameterMap.put(key, newValue);
>  }
>  }
>  parameters = modParameterMap;
>  } catch (UnsupportedOperationException e) {
>  // parameter map is immutable, just use it "as is"
>  }
>  return tf.getProcessedTemplateContent(t, new Hashtable(parameters), 
> element);
>  } else {
>  return tf.getProcessedTemplateContent(t, null, element);
>  }
>  }
>  ----8<----
>  Claus
>
>  OpenCms links & API's: http://www.codedroids.com/community/opencms
>  --
>  Claus Priisholm
>  +45 48 22 46 46
>  cpr <you know what> codedroids.com
>  http://www.codedroids.com
>
>
>
>  On 17/8-2004, at 13.07, Niina Meronen wrote:
>
> Hi everybody,
>
>   
>
>  I found a question below from the mail archive when struggling with 
> similar problem but there were no answers. So, is there anybody who 
> knows the reason or can explain how to avoid that problem? In my case 
> we are using OpenCMS 5.0.1., and the problem is that the content of 
> file that is called (usually index.html) is replaced by previous 
> file’s content (smaller position in navigation). In other words, 
> previous file’s content is shown twice when trying to include several 
> html-pages in one template. The only exception is when the file that 
> is called is the first one in navigation, then the content of all the 
> files is shown correctly!
>
>   
>
>  I would really apreciate the answer, thanks in advance!
>
>   
>
>  Niina Meronen
>
> ---
>
>  
>
> Frank Wunderlichk.frank.wunderlich at gmx.de
> Mon Jun 2 18:55:01 CEST 2003
>  • Previous message: [opencms-dev] projectId of tempfileproject
>  • Next message: [opencms-dev] Deleting old folders during sync
>  • Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
>
> Hi,
>  
> I've got the following problem:
>  
> I have got a master-jsp-template, that shall dynamically include other
> html-pages (resp. page-fragments), that have their own jsp-template.
> That means, both, the including and the included page are editable via
> opencms.
>  
> Unfortunatly the bodycontent of the main-page is not accessible 
> anymore,
> after I have included the other page.
> Instead of showing the bodycontent of the main-page, the bodycontent of
> the included page is shown again.
>  
> Example:
>  
> <cms:include element="body" />              // The correct bodycontent
> of my page is displayed
> <% cms.include(otherEditableHtmlFile); %>   // The content of the
> included page is displayed
>  <cms:include element="body" />              // The content of the
> included page is shown again!!
>  
> Looks like some unwanted sideeffect to me...
> Or am I doing something the wrong way?
>  
> Thanks in advance,
> Frank.
>
>   
>
>   
>
>  --
>  Niina Meronen
>  Service Manager
>  Cidercone Wireless
>  Paciuksenkatu 21
>  FI-00270 Helsinki
>  phone +358 9 477 41 610
>  fax +358 9 477 41 666
> niina.meronen at cidercone.com
>  www.cidercone.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
>
>
> _______________________________________________
> 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
--
Claus Priisholm, CodeDroids ApS
+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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 17347 bytes
Desc: not available
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20040819/79308bd1/attachment.bin>


More information about the opencms-dev mailing list