BlockMacro (Velocity 1.7 API)
Keywords: org.apache.velocity.runtime.directive.BlockMacro class

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.velocity.runtime.directive
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

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$
Author:
  Jarkko Viinamaki

Nested Class Summary

Nested classes inherited from class org.apache.velocity.runtime.directive.Block
`Block.Reference`

Field Summary

Fields inherited from class org.apache.velocity.runtime.directive.Block
`block, key, log, maxDepth`

Fields inherited from class org.apache.velocity.runtime.directive.Directive
`rsvc`

Fields inherited from interface org.apache.velocity.runtime.directive.DirectiveConstants
`BLOCK, LINE`

Constructor Summary
`BlockMacro(String name)`

Method Summary
`String` | `getName()` Return the name of this directive.
`String` | `getScopeName()` Override to use the macro name, since it is within an #@myMacro() ...
`void` | `init(RuntimeServices rs, 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.Block
`getType, id, render`

Methods inherited from class org.apache.velocity.runtime.directive.Directive
`getColumn, getLine, getTemplateName, isScopeProvided, makeScope, postRender, preRender, setLocation, setLocation`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### BlockMacro

    public BlockMacro(String name)

Method Detail

### getName

    public 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 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`

### init

    public void init(RuntimeServices rs,
                     InternalContextAdapter context,
                     Node node)
              throws TemplateInitException

  Initializes the directive.

  Overrides:
    `init` in class `Block`
  Parameters:
    `rs` -
    `context` -
    `node` -
  Throws:
    `TemplateInitException`

### render

    public boolean render(InternalContextAdapter context,
                          Writer writer,
                          Node node)
                   throws 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:
    `IOException`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000-2010 Apache Software Foundation. All Rights Reserved.