Extends
lithium\core\Object
Executes a named rendering process by running each process step in sequence and aggregating
the results. The `View` class comes with 3 built-in processes: `'all'`, `'template'`, and
`'element'`. The `'all'` process is the default two-step rendered view, where a template is
wrapped in a layout containing a header and footer.
Parameters
- string $process A named set of rendering steps defined in the `$_processes` array.
- array $data An associative array of data to be rendered in the set of templates.
- array $options Options used when rendering. Available keys are as follows: - `'type'` _string_: The type of content to render. Defaults to `'html'`. - `'layout'` _string_: The name of the layout to use in the default two-step rendering process. Defaults to `null`. - `'template'` _string_: The name of the template to render. Defaults to `null`. - `'context'` _array_: An associative array of information to inject into the rendering context. - `'paths'` _array_: A nested array of paths to use for rendering steps. The top-level keys should match the `'path'` key in a step configuration (i.e.: `'template'`, `'layout'`, or `'element'`), and the second level is an array of path template strings to search (can be a string if there's only one path). These path strings generally take the following form: `'{:library}/views/{:controller}/{:template}.{:type}.php'`. These template strings are specific to the `File` loader, but can take any form useful to the template loader being used.
Returns
string Returns the result of the rendering process, typically by rendering a template first, then rendering a layout (using the default configuration of the `'all'` process).Source
public function render($process, array $data = array(), array $options = array()) {
$defaults = array(
'type' => 'html',
'layout' => null,
'template' => null,
'context' => array(),
'paths' => array(),
'data' => array()
);
$options += $defaults;
$data += $options['data'];
$paths = $options['paths'];
unset($options['data'], $options['paths']);
$params = array_filter($options, function($val) { return $val && is_string($val); });
$result = null;
foreach ($this->_process($process, $params) as $name => $step) {
if (isset($paths[$name]) && $paths[$name] === false) {
continue;
}
if (!$this->_conditions($step, $params, $data, $options)) {
continue;
}
if ($step['multi'] && isset($options[$name])) {
foreach ((array) $options[$name] as $value) {
$params[$name] = $value;
$result = $this->_step($step, $params, $data, $options);
}
continue;
}
$result = $this->_step((array) $step, $params, $data, $options);
}
return $result;
}