# Capsule

Capsule is a simple "template" engine that essentially provides an isolated context for PHP scripts.

There is no special templating language, and therefore no limitations to what can be accomplished within templates. The main purpose of Capsule is to separate the business logic from display / output logic.

author | Hans Lellelid hans@xmpl.org
package | phing.lib

### Methods

## __construct

    __construct()

## Clears one or several or all variables.

    clear(mixed $which = null) : void

### Arguments

#### $which

`mixed`

String name of var, or array of names.

## Low overhead (no output buffering) method to simply dump template to buffer.

    display(string $__template) : void

throws | if template cannot be found

### Arguments

#### $__template

`string`

## Gets value of specified var or NULL if var has not been put().

    get(string $name) : mixed

### Arguments

#### $name

`string`

Variable name to retrieve.

### Response

`mixed`

## Get basepath to use for output file creation.

    getOutputDirectory() : string

### Response

`string`

## Get the basepath to use for template lookups.

    getTemplatePath() : string

### Response

`string`

## Fetches the results of a tempalte parse and either returns the string or writes results to a specified output file.

    parse(string $template, string $outputFile = null, boolean $append = false) : string

throws | if template not found.

### Arguments

#### $template

`string`

The template filename (relative to templatePath or absolute).

#### $outputFile

`string`

If specified, contents of template will also be written to this file.

#### $append

`boolean`

Should output be appended to source file?

### Response

`string`

The "parsed" template output.

## Adds a variable to the context.

    put(string $name, mixed $value)

Resulting template will have access to ${$name$} variable.

### Arguments

#### $name

`string`

#### $value

`mixed`

## Merges in passed hash to vars array.

    putAll(array $vars, boolean $recursiveMerge = false) : void

Given an array like:

           array(     'myvar' => 'Hello',
                   'myvar2' => 'Hello')

Resulting template will have access to $myvar and $myvar2.

### Arguments

#### $vars

`array`

#### $recursiveMerge

`boolean`

Should matching keys be recursively merged?

## Makes a copy of the value and puts it into the context.

    putCopy(string $name, mixed $value)

This is primarily to force copying (cloning) of objects, rather than the default behavior which is to assign them by reference.

### Arguments

#### $name

`string`

#### $value

`mixed`

## Put a variable into the context, assigning it by reference.

    putRef( $name,  &$value)

This means that if the template modifies the variable, then it will also be modified in the context.

### Arguments

#### $name

``

#### $value

``

## This returns a "best guess" path for the given file.

    resolvePath(string $file, string $basepath) : string

### Arguments

#### $file

`string`

File name or possibly absolute path.

#### $basepath

`string`

The basepath that should be prepended if $file is not absolute.

### Response

`string`

"Best guess" path for this file.

## Set a basepath to use for output file creation.

    setOutputDirectory(string $v)

### Arguments

#### $v

`string`

## Set the basepath to use for template lookups.

    setTemplatePath(string $v)

### Arguments

#### $v

`string`

### Properties

## Look for templates here (if relative path provided).

    templatePath : string

var |

### Type(s)

`string`

## Where should output files be written? (This is named inconsistently to be compatible w/ Texen.)

    outputDirectory : string

var |

### Type(s)

`string`

## The variables that can be used by the templates.

    vars : array

var | Hash of variables.

### Type(s)

`array`

## Has template been initialized.

    initialized : boolean

var |

### Type(s)

`boolean`

## Stores the pre-parse() include_path.

    old_include_path : string

var |

### Type(s)

`string`