You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Nathan Quirynen <na...@pensionarchitects.be> on 2013/08/07 11:33:14 UTC
Conditional wrapping html element
Hi,
I want to add a div that wraps my content based on a condition:
<t:if test="test">
<div class="cssclass">
</t:if>
... content ...
<t:if test="test">
</div>
</t:if>
This is not possible as it will give following exception:
/org.xml.sax.SAXParseException/
/The element type "div" must be terminated by the matching end-tag "</div>".
/For my use case I can make a property for the css class and base it on
the condition:
<div class="${cssClass}">
... content ...
</div>
public String getCssClass() {
return test ? "cssclass" : "";
}
But I was just wondering if there is a way of adding a wrapping element
conditionally as I showed at the top.
Nathan
Re: Conditional wrapping html element
Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Wed, 07 Aug 2013 06:33:14 -0300, Nathan Quirynen
<na...@pensionarchitects.be> wrote:
> Hi,
Hi!
If this is a common case, I'd write a mixin for that.
--
Thiago H. de Paula Figueiredo
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Conditional wrapping html element
Posted by Lance Java <la...@googlemail.com>.
Nice! Much less hacky than my approach.
I'm waiting for Thiago's imminent comment regarding <t:else> :)
On 7 Aug 2013 10:56, "Dmitry Gusev" <dm...@gmail.com> wrote:
> Or you can use blocks and delegate:
>
> <t:block id="contentBlock">
> Your content
> </t:block>
>
> <t:if test="condition">
> <div class="cssclass">
> <t:delegate to="block:contentBlock" />
> </div>
> <p:else>
> <t:delegate to="block:contentBlock" />
> </p:else>
> </t:if>
>
> On Wed, Aug 7, 2013 at 1:47 PM, Lance Java <lance.java@googlemail.com
> >wrote:
>
> > You'll have to use the OutputRaw component or MarkupWriter.writeRaw(...)
> >
> > Note that when passing the value parameter to OutputRaw you will need to
> > escape <, > and "
> > On 7 Aug 2013 10:33, "Nathan Quirynen" <na...@pensionarchitects.be>
> > wrote:
> >
> > > Hi,
> > >
> > > I want to add a div that wraps my content based on a condition:
> > >
> > > <t:if test="test">
> > > <div class="cssclass">
> > > </t:if>
> > >
> > > ... content ...
> > >
> > > <t:if test="test">
> > > </div>
> > > </t:if>
> > >
> > >
> > > This is not possible as it will give following exception:
> > >
> > > /org.xml.sax.**SAXParseException/
> > > /The element type "div" must be terminated by the matching end-tag
> > > "</div>".
> > >
> > > /For my use case I can make a property for the css class and base it on
> > > the condition:
> > >
> > > <div class="${cssClass}">
> > > ... content ...
> > > </div>
> > >
> > > public String getCssClass() {
> > > return test ? "cssclass" : "";
> > > }
> > >
> > > But I was just wondering if there is a way of adding a wrapping element
> > > conditionally as I showed at the top.
> > >
> > > Nathan
> > >
> > >
> >
>
>
>
> --
> Dmitry Gusev
>
> AnjLab Team
> http://anjlab.com
>
Re: Conditional wrapping html element
Posted by Steve Eynon <st...@alienfactory.co.uk>.
You could create a simple component that optionally renders the div
element. Something like:
public class IfDiv {
@Parameter
private boolean test;
void setupRender(MarkupWriter writer) {
if (test)
writer.element("div");
}
void afterRender(MarkupWriter writer) {
if (test)
writer.end();
}
}
Steve.
On 7 August 2013 10:54, Dmitry Gusev <dm...@gmail.com> wrote:
> Or you can use blocks and delegate:
>
> <t:block id="contentBlock">
> Your content
> </t:block>
>
> <t:if test="condition">
> <div class="cssclass">
> <t:delegate to="block:contentBlock" />
> </div>
> <p:else>
> <t:delegate to="block:contentBlock" />
> </p:else>
> </t:if>
>
> On Wed, Aug 7, 2013 at 1:47 PM, Lance Java <lance.java@googlemail.com
> >wrote:
>
> > You'll have to use the OutputRaw component or MarkupWriter.writeRaw(...)
> >
> > Note that when passing the value parameter to OutputRaw you will need to
> > escape <, > and "
> > On 7 Aug 2013 10:33, "Nathan Quirynen" <na...@pensionarchitects.be>
> > wrote:
> >
> > > Hi,
> > >
> > > I want to add a div that wraps my content based on a condition:
> > >
> > > <t:if test="test">
> > > <div class="cssclass">
> > > </t:if>
> > >
> > > ... content ...
> > >
> > > <t:if test="test">
> > > </div>
> > > </t:if>
> > >
> > >
> > > This is not possible as it will give following exception:
> > >
> > > /org.xml.sax.**SAXParseException/
> > > /The element type "div" must be terminated by the matching end-tag
> > > "</div>".
> > >
> > > /For my use case I can make a property for the css class and base it on
> > > the condition:
> > >
> > > <div class="${cssClass}">
> > > ... content ...
> > > </div>
> > >
> > > public String getCssClass() {
> > > return test ? "cssclass" : "";
> > > }
> > >
> > > But I was just wondering if there is a way of adding a wrapping element
> > > conditionally as I showed at the top.
> > >
> > > Nathan
> > >
> > >
> >
>
>
>
> --
> Dmitry Gusev
>
> AnjLab Team
> http://anjlab.com
>
Re: Conditional wrapping html element
Posted by Dmitry Gusev <dm...@gmail.com>.
Or you can use blocks and delegate:
<t:block id="contentBlock">
Your content
</t:block>
<t:if test="condition">
<div class="cssclass">
<t:delegate to="block:contentBlock" />
</div>
<p:else>
<t:delegate to="block:contentBlock" />
</p:else>
</t:if>
On Wed, Aug 7, 2013 at 1:47 PM, Lance Java <la...@googlemail.com>wrote:
> You'll have to use the OutputRaw component or MarkupWriter.writeRaw(...)
>
> Note that when passing the value parameter to OutputRaw you will need to
> escape <, > and "
> On 7 Aug 2013 10:33, "Nathan Quirynen" <na...@pensionarchitects.be>
> wrote:
>
> > Hi,
> >
> > I want to add a div that wraps my content based on a condition:
> >
> > <t:if test="test">
> > <div class="cssclass">
> > </t:if>
> >
> > ... content ...
> >
> > <t:if test="test">
> > </div>
> > </t:if>
> >
> >
> > This is not possible as it will give following exception:
> >
> > /org.xml.sax.**SAXParseException/
> > /The element type "div" must be terminated by the matching end-tag
> > "</div>".
> >
> > /For my use case I can make a property for the css class and base it on
> > the condition:
> >
> > <div class="${cssClass}">
> > ... content ...
> > </div>
> >
> > public String getCssClass() {
> > return test ? "cssclass" : "";
> > }
> >
> > But I was just wondering if there is a way of adding a wrapping element
> > conditionally as I showed at the top.
> >
> > Nathan
> >
> >
>
--
Dmitry Gusev
AnjLab Team
http://anjlab.com
Re: Conditional wrapping html element
Posted by Lance Java <la...@googlemail.com>.
You'll have to use the OutputRaw component or MarkupWriter.writeRaw(...)
Note that when passing the value parameter to OutputRaw you will need to
escape <, > and "
On 7 Aug 2013 10:33, "Nathan Quirynen" <na...@pensionarchitects.be> wrote:
> Hi,
>
> I want to add a div that wraps my content based on a condition:
>
> <t:if test="test">
> <div class="cssclass">
> </t:if>
>
> ... content ...
>
> <t:if test="test">
> </div>
> </t:if>
>
>
> This is not possible as it will give following exception:
>
> /org.xml.sax.**SAXParseException/
> /The element type "div" must be terminated by the matching end-tag
> "</div>".
>
> /For my use case I can make a property for the css class and base it on
> the condition:
>
> <div class="${cssClass}">
> ... content ...
> </div>
>
> public String getCssClass() {
> return test ? "cssclass" : "";
> }
>
> But I was just wondering if there is a way of adding a wrapping element
> conditionally as I showed at the top.
>
> Nathan
>
>