Class BlockMacro

  • All Implemented Interfaces:
    java.lang.Cloneable, DirectiveConstants

    public class BlockMacro
    extends Block
    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>
     #end
     
    Will 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$
    • Field Detail

      • name

        private java.lang.String name
    • Constructor Detail

      • BlockMacro

        public BlockMacro​(java.lang.String name)
    • Method Detail

      • getName

        public java.lang.String getName()
        Description copied from class: Directive
        Return the name of this directive.
        Specified by:
        getName in class Directive
        Returns:
        The name of this directive.
      • getScopeName

        public java.lang.String 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 class Directive
      • render

        public boolean render​(InternalContextAdapter context,
                              java.io.Writer writer,
                              Node node)
                       throws java.io.IOException
        Renders content using the selected macro and the passed AST body.
        Specified by:
        render in class Directive
        Parameters:
        context -
        writer -
        node -
        Returns:
        True if the directive rendered successfully.
        Throws:
        java.io.IOException