lithium\template\View::render PHP Method

render() public method

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.
See also: lithium\template\View::_conditions()
See also: lithium\template\View::$_processes
See also: lithium\template\View::$_steps
public render ( string $process, array $data = [], array $options = [] ) : string
$process string A named set of rendering steps defined in the `$_processes` array.
$data array An associative array of data to be rendered in the set of templates.
$options array 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.
return 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).
    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;
    }

Usage Example

Beispiel #1
0
 public function testFullRenderNoLayout()
 {
     $view = new View(array('loader' => 'Simple', 'renderer' => 'Simple'));
     $result = $view->render('all', array('type' => 'auth', 'success' => 'true'), array('template' => '<{:type}>{:success}</{:type}>'));
     $expected = '<auth>true</auth>';
     $this->assertEqual($expected, $result);
 }
All Usage Examples Of lithium\template\View::render