tags:

views:

392

answers:

2

I have one layout component for all my pages, I want to switch this component based on the user desire. I don't want to add a property to each page to return the current layout component.

+1  A: 

Assuming you have a fixed number of layouts, you can use blocks. Your layout.tml would look something like:

   <t:delegate to="layout"/>

   <t:block id="layout1">
     <body>...</body>
   </t:block>

   <t:block id="layout2">
     <body>...</body>
   </t:block>

Your layout.java would have:

  public Object getLayout() {
    if (...) {
      return _layout1;
    } else {
      return _layout2;
    }
  }

  @Inject
  private Block _layout1;

  @Inject
  private Block _layout2;
Brian Deterling
Great,But I don't want to put all the layouts in one .tml file..Is there a way to delegate to a component???
Bahaa Zaid
Yes, the target of delegate can be a block or a component. So you could just define a component for each layout you need. I think you'd still need to list all those components in the main layout.tml but the html could be in the individual components.
Brian Deterling
A: 

Hello

It is possible to give a default value for the t:delegate block after loading the page?

alan earl

related questions