Class BlockMacro
java.lang.Object
org.apache.velocity.runtime.directive.Directive
org.apache.velocity.runtime.directive.Block
org.apache.velocity.runtime.directive.BlockMacro
- All Implemented Interfaces:
Cloneable
,DirectiveConstants
BlockMacro directive is used to invoke Velocity macros with normal parameters and a macro body.
The macro can then refer to the passed body AST. This directive can be used as a "decorator". Body AST can contain any valid Velocity syntax. An example:
#set($foobar = "yeah!") #macro(strong $txt) <strong>$bodyContent</strong> $txt #end #@strong($foobar) <u>This text is underlined and bold</u> #endWill print:
<strong><u>This text is underlined and bold<u></strong> yeah!bodyContent reference name is configurable (see velocity.properties).
- Since:
- 1.7
- Version:
- $Id$
- Author:
- Jarkko Viinamaki
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.velocity.runtime.directive.Block
Block.Reference
-
Field Summary
Fields inherited from interface org.apache.velocity.runtime.directive.DirectiveConstants
BLOCK, LINE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiongetName()
Return the name of this directive.Override to use the macro name, since it is within an #@myMacro() ...void
init
(RuntimeServices rs, String macroName, InternalContextAdapter context, Node node) Initializes the directive.boolean
render
(InternalContextAdapter context, Writer writer, Node node) Renders content using the selected macro and the passed AST body.Methods inherited from class org.apache.velocity.runtime.directive.Directive
checkArgs, getColumn, getLine, getTemplate, getTemplateName, isScopeProvided, makeScope, postRender, preRender, setLocation, setLocation
-
Constructor Details
-
BlockMacro
public BlockMacro()
-
-
Method Details
-
getName
Description copied from class:Directive
Return the name of this directive. -
getScopeName
Override to use the macro name, since it is within an #@myMacro() ... #end block that the scope in question would be used.- Overrides:
getScopeName
in classDirective
- Returns:
- the name to be used when a scope control is provided for this directive.
-
init
public void init(RuntimeServices rs, String macroName, InternalContextAdapter context, Node node) throws TemplateInitException Initializes the directive.- Parameters:
rs
-macroName
-context
-node
-- Throws:
TemplateInitException
-
render
Renders content using the selected macro and the passed AST body.- Specified by:
render
in classDirective
- Parameters:
context
-writer
-node
-- Returns:
- True if the directive rendered successfully.
- Throws:
IOException
-