Transform directive - Apache FreeMarker Manual

Unsupported web browser - Use a modern browser to view this website!

- Home
- Manual
- Java API

- Contribute
- Report a Bug
- Download

Manual
Previous Next

# Transform directive

## Synopsis

    <transform transVar>
      ...
    </transform>
    or
    <transform transVar name1=value1 name2=value2 ... nameN=valueN>
      ...
    </transform>

Where:

- `transVar`: Expression evaluates to a transform
- `name1`, `name2`, ... `nameN`: Name of parameters. Literal value, not expression.
- `value1`, `value2`, ... `valueN`: Expressions evaluate to the values of parameters

## Description

Note:

This directive is still working, but deprecated. You may want to read about user-defined directive calls to see the replacement.

Captures the output generated inside its body (i.e. between its start-tag and end-tag), and let the given transform modify it before it is written to the final output.

Example:

Template

    <p>A very simple HTML file:
    <pre>
    <transform html_escape>
    <html>
      <body>
        <p>Hello word!
      </body>
    </html>
    </transform>
    </pre>

the output will be:

Output

    <p>A very simple HTML file:
    <pre>
    &lt;html&gt;
      &lt;body&gt;
        &lt;p&gt;Hello word!
      &lt;/body&gt;
    &lt;/html&gt;
    </pre>

Some transforms may take parameters. The name and meaning of parameters depends on the transform in question. For example here we give a parameter called "var":

Template

    <#-- This transform stores the output in the variable x,
         rather than sending it to the output -->
    <transform capture_output var="x">
    some test
    </transform>

It is the task of the programmers to put the necessary transforms into the data-model. For the name and usage of accessible transforms ask the programmers. Initially there is a shared variable for most transforms in the `freemarker.template.utility` package. For more information see: Programmer's Guide/The Configuration/Shared variables

Previous Next