Empty body?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Empty body?

Manuel Sugawara-2
Hi

I'm working in a menu component, similar to the one in the howtos. The
menuItem template looks like:

    <t:content>
      <li>
        <t:if test="isPage">
          <t:pageLink page="prop:page"
class="prop:className">${pageTitle}</t:pageLink>
          <p:else>
            <a href="#" class="${className}">${pageTitle}</a>
          </p:else>
        </t:if>
        <ul>
          <t:body/>
        </ul>
      </li>
    </t:content>

however this template still renders an empty <ul> if there is no body. I
would like to conditionally display the ul depending if there is a body or
not. Something like:

        <t:if test="hasBody">
          <ul>
            <t:body/>
          </ul>
        </t:if>

Now, I have solved this implementing the hasBody method like:

    @Inject
    private ComponentResources resources;

    public boolean getHasBody() {
        Block block = resources.getBody();
        if ("<PlaceholderBlock>".equals(block.toString())) {
            return false;
        }
        return true;
    }

This works but seems a bit flaky. Is there a better way to figure out if a
block is empty?

Regards,
Manuel.
Reply | Threaded
Open this post in threaded view
|

Re: Empty body?

Mats Andersson-2
Hi Manuel,

Seems more logical to have the <ul> at the same level as the <li>. That
way you will know if you have generated any <li>.

BR
Mats



Manuel Sugawara skrev:

> Hi
>
> I'm working in a menu component, similar to the one in the howtos. The
> menuItem template looks like:
>
>     <t:content>
>       <li>
>         <t:if test="isPage">
>           <t:pageLink page="prop:page"
> class="prop:className">${pageTitle}</t:pageLink>
>           <p:else>
>             <a href="#" class="${className}">${pageTitle}</a>
>           </p:else>
>         </t:if>
>         <ul>
>           <t:body/>
>         </ul>
>       </li>
>     </t:content>
>
> however this template still renders an empty <ul> if there is no body. I
> would like to conditionally display the ul depending if there is a body or
> not. Something like:
>
>         <t:if test="hasBody">
>           <ul>
>             <t:body/>
>           </ul>
>         </t:if>
>
> Now, I have solved this implementing the hasBody method like:
>
>     @Inject
>     private ComponentResources resources;
>
>     public boolean getHasBody() {
>         Block block = resources.getBody();
>         if ("<PlaceholderBlock>".equals(block.toString())) {
>             return false;
>         }
>         return true;
>     }
>
> This works but seems a bit flaky. Is there a better way to figure out if a
> block is empty?
>
> Regards,
> Manuel.
>
>  

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Empty body?

Robert Hailey
In reply to this post by Manuel Sugawara-2

On Mar 12, 2010, at 1:20 PM, Manuel Sugawara wrote:

> Hi
>
> I'm working in a menu component, similar to the one in the howtos. The
> menuItem template looks like:

I am not able to find such a menu component in the howtos. Can you  
provide a link please?

--
Robert Hailey



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Empty body?

Manuel Sugawara-2
On Mon, Mar 15, 2010 at 5:07 PM, Robert Hailey <[hidden email]>wrote:

>
> On Mar 12, 2010, at 1:20 PM, Manuel Sugawara wrote:
>
>  Hi
>>
>> I'm working in a menu component, similar to the one in the howtos. The
>> menuItem template looks like:
>>
>
> I am not able to find such a menu component in the howtos. Can you provide
> a link please?
>

 http://wiki.apache.org/tapestry/Tapestry5LayoutWithMenu

Regards,
Manuel.