Step 3. The Use

The use of a macro component is no different than others.

<window>
    <username/>    
</window>

Pass Properties

Like an ordinary component, you can specify properties (aka., attributes) when using a macro component as follows.

<?component name="username" macroURI="/WEB-INF/macros/username.zul"?>
<window>
    <username who="John"/>    
</window>

All these properties specified are stored in a map that is then passed to the template via a variable called arg. Then, in the template, you could access these properties as follows.

<hbox>
    Username: <textbox value="${arg.who}"/>    
</hbox>

Note: arg is available only when rendering the macro page. To access in the event listener, you have to use getDynamicProperty instead. Refer to the Provide Additional Methods section for more details.

arg.includer

In additions to the specified properties (aka., attributes), a property called arg.includer is always passed to represent the parent of the components defined in a macro template.

If a regular macro is created, arg.includer is the macro component itself. If an inline macro is created, arg.includer is the parent component, if any. Refer to the Inline Macros section for more information.

In the above example, arg.includer represents the regular macro component, <username who="John"/>, and is the parent of <hbox> (defined in username.zul).