[Hippo-cms7-user] Template composer containers, hst:include and empty outputs

Woonsan Ko w.ko at onehippo.com
Mon Jun 18 21:20:00 CEST 2012


Hi Minos / Ard,

I gave another thought about the solution. It seems more complex than I 
thought at first.
Please see my comments below.

On 6/18/12 10:23 AM, Woonsan Ko wrote:
> Hi Minos / Ard,
>
> On 6/18/12 3:56 AM, Ard Schrijvers wrote:
>> For the near future, I introducing a var in the hst:include might be
>> useful. This var could contain the byte[] of the child output
>>
>> <hst:include ref="..." var="test>
>> <c:if test='var is not empty byte[]'>
>> <div class="hst-container-item">${test}</div>
>> </c:if>
>> </hst:include>
>
> This sounds good to me.
> But, the variable should be type of string, instead of byte[], because
> the response state already manages the output as char[] and string
> should be better in JSTL.
>
> @Minos, would the following solve your problem then?
>
> <hst:include ref="aChild" var="aChildOut" scope="page">
> <c:if test="${not empty fn:trim(aChild)}">
> <div class="hst-container-item">${aChildOut}</div>
> </c:if>
> </hst:include>

I don't see any reason why <hst:include/> should be able to contain 
other tags inside.
So, I'd like to change the example simpler like the following:

<hst:include ref="aChild" var="aChildOut" />
<c:if test="${not empty fn:trim(aChildOut)}">
   <div class="hst-container-item">${aChildOut}</div>
</c:if>

First, it doesn't need to contain any other tags inside.
Second, it's a conceptual problem. Currently the <hst:include/> tag 
flushes the child content on #doEndTag(); if we want to allow tag 
inclusions inside, then we have to do it in #doStartTag() when storing 
to a variable because the inner tag may want to use the variable. But, 
this seems to confuse the behavior of the tag conceptually. What are the 
inner tags inside *include* tag for? So, to avoid any conceptual 
confusions, I would like to avoid unnecessary tag inclusions inside the 
tag like the example above.

In addition, I'd like to explain the behavior of <hst:include/> a bit more.
<hst:include/> tag does not only write the child content, but also 
flushes invisible stuffs such as cookie, header, etc.
Therefore, in most cases, it is recommended to flush all the child 
contents by using <hst:include/> even though a child content doesn't 
write anything visible.
In this sense, how can we define the behavior when the tag has 'var' 
attribute (e.g., <hst:include var="aChildOut" />)?
I think the behavior must be 1) to flush all invisible stuffs such as 
cookie and header, 2) to store the rendered content into the variable, 
and 3) the inclusion cannot happen twice as same as the original 
behavior of <hst:include/> because it's *flushed*.

In summary, <hst:include/> tag with 'var' attribute will mean, "flushing 
into a variable instead of the default writer".

Lastly, I forgot that the content in the response state could exist as 
byte[] as well as char[], depending on the output invokers (whether 
using #getOutputStream() or #getWriter()). Normally they use char[] by 
invoking #getWriter() via JSP pages, but it is still possible to use 
byte[] with servlet templates.
Anyway, because still we'd better support both options, I think we can 
create a wrapper object of the rendered content. The wrapper object 
should implement #toString() (and #getBytes()), so it can be directly 
used in the <c:out/> or fn:trim() function.

What do you think?

Kind regards,

Woonsan

>
>
> Regards,
>
> Woonsan
>


-- 
w.ko at onehippo.com     www.onehippo.com
Boston - 1 Broadway, Cambridge, MA 02142
Amsterdam - Oosteinde 11, 1017 WT Amsterdam
US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466



More information about the Hippo-cms7-user mailing list