Search code examples
wicket-6

Transclude HTML in Apache Wicket component


I want to transclude html in a component, similar on how angularjs does with transclude:true (directives).

Suppose I have this html

<div wicket:id="myComponent> My content </div>

I want the component to write "My content" where I specify. In MyComponent.html:

<wicket:panel>   
//Some other code
TRANSCLUDE HERE: "My content" should be here.
</wicket:panel>

Thanks in advance


Solution

  • This is what org.apache.wicket.markup.html.border.Border component does.

    The markup of a Border looks like:

    <wicket:border>
      // some HTML with or without wicket:id here
     <wicket:body/>
      // some more HTML with or without wicket:id here
    <wicket:border>
    

    At the usage site you have:

    <div wicket:id="myborder">
       // anything here will replace <wicket:body/> in the snippet above
    </div>