Property | Type | Description | |
---|---|---|---|
$_autoConfig | array | These configuration variables will automatically be assigned to their corresponding protected properties when the object is initialized. | |
$_classes | array | Renderer's dependencies. These classes are used by the output handlers to generate URLs for dynamic resources and static assets. | |
$_context | array | Context values that exist across all templates rendered in this context. These values are usually rendered in the layout template after all other values have rendered. | |
$_data | array | An array containing any additional variables to be injected into view templates. This allows local variables to be communicated between multiple templates (i.e. an element and a layout) which are using the same rendering context. | |
$_handlers | array | Automatically matches up template strings by name to output handlers. A handler can either be a string, which represents a method name of the helper, or it can be a closure or callable object. A handler takes 3 parameters: the value to be filtered, the name of the helper method that triggered the handler, and the array of options passed to the _render(). These handlers are shared among all helper objects, and are automatically triggered whenever a helper method renders a template string (using _render()) and a key which is to be embedded in the template string matches an array key of a corresponding handler. | |
$_helpers | array | Contains the list of helpers currently in use by this rendering context. Helpers are loaded via the helper() method, which is called by Renderer::__get(), allowing for on-demand loading of helpers. | |
$_options | array | Available options accepted by template\View::render(), used when rendering. | |
$_request | The Request object instance, if applicable. | ||
$_response | The Response object instance, if applicable. | ||
$_strings | array | Aggregates named string templates used by helpers. Can be overridden to change the default strings a helper uses. | |
$_vars | Variables that have been set from a view/element/layout/etc. that should be available to the same rendering context. | ||
$_view | object | Holds an instance of the View object that created this rendering context. See the view() method for more details. |
Method | Description | |
---|---|---|
__call ( string $method, array $params ) : mixed | Dispatches method calls for (a) rendering context values or (b) applying handlers to pieces of content. If $method is a key in Renderer::$_context, the corresponding context value will be returned (with the value run through a matching handler if one is available). If $method is a key in Renderer::$_handlers, the value passed as the first parameter in the method call will be passed through the handler and returned. | |
__construct ( array $config = [] ) : void | Constructor. | |
__get ( string $property ) : mixed | Returns a helper object or context value by name. | |
__isset ( string $property ) : boolean | Magic __isset method. | |
applyHandler ( object $helper, string $method, string $name, mixed $value, array $options = [] ) : mixed | Filters a piece of content through a content handler. A handler can be: - a string containing the name of a method defined in $helper. The method is called with 3 parameters: the value to be handled, the helper method called ($method) and the $options that were passed into applyHandler. | |
context ( string $property = null ) : mixed | Returns either one or all context values for this rendering context. Context values persist across all templates rendered in the current context, and are usually outputted in a layout template. | |
data ( ) : array | Returns all variables and their values that have been set. | |
handlers ( mixed $handlers = null ) : mixed | Gets or adds content handlers from/to this rendering context, depending on the value of $handlers. For more on how to implement handlers and the various types, see applyHandler(). | |
helper ( string $name, array $config = [] ) : object | Brokers access to helpers attached to this rendering context, and loads helpers on-demand if they are not available. | |
render ( string $template, array | string $data = [], array $options = [] ) : string | Render the template with given data. Abstract; must be added to subclasses. | |
request ( ) : object | Returns the Request object associated with this rendering context. | |
respondsTo ( string $method, boolean $internal = false ) : boolean | Determines if a given method can be called. | |
response ( ) : object | Returns the Response object associated with this rendering context. | |
set ( array $data = [] ) : void | Allows variables to be set by one template and used in subsequent templates rendered using the same context. For example, a variable can be set in a template and used in an element rendered within a template, or an element or template could set a variable which would be made available in the layout. | |
strings ( mixed $strings = null ) : mixed | Manages template strings. | |
view ( ) : object | Retuns the View object that controls this rendering context's instance. This can be used, for example, to render view elements, i.e. view()->render('element' $name); ?>. |
Method | Description | |
---|---|---|
_init ( ) : void | Sets the default output handlers for string template inputs. | |
_render ( string $type, string $template, array $data = [], array $options = [] ) : string | Shortcut method used to render elements and other nested templates from inside the templating layer. |
public __construct ( array $config = [] ) : void | ||
$config | array | Available configuration options are: - `view`: The `View` object associated with this renderer. - `strings`: String templates used by helpers. - `handlers`: An array of output handlers for string template inputs. - `request`: The `Request` object associated with this renderer and passed to the defined handlers. - `response`: The `Response` object associated with this renderer. - `context`: An array of the current rendering context data, including `content`, `title`, `scripts`, `head` and `styles`. |
return | void |
protected _render ( string $type, string $template, array $data = [], array $options = [] ) : string | ||
$type | string | The type of template to render, usually either `'element'` or `'template'`. Indicates the process used to render the content. See `lithium\template\View::$_processes` for more info. |
$template | string | The template file name. For example, if `'header'` is passed, and `$type` is set to `'element'`, then the template rendered will be `views/elements/header.html.php` (assuming the default configuration). |
$data | array | An array of any other local variables that should be injected into the template. By default, only the values used to render the current template will be sent. If `$data` is non-empty, both sets of variables will be merged. |
$options | array | Any options accepted by `template\View::render()`. |
return | string | Returns a the rendered template content as a string. |
public applyHandler ( object $helper, string $method, string $name, mixed $value, array $options = [] ) : mixed | ||
$helper | object | The instance of the object (usually a helper) that is invoking |
$method | string | The object (helper) method which is applying the handler to the content |
$name | string | The name of the value to which the handler is applied, i.e. `'url'`, `'path'` or `'title'`. |
$value | mixed | The value to be transformed by the handler, which is ultimately returned. |
$options | array | Any options which should be passed to the handler used in this call. |
return | mixed | The transformed value of `$value`, after it has been processed by a handler. |
public context ( string $property = null ) : mixed | ||
$property | string | If unspecified, an associative array of all context values is returned. If a string is specified, the context value matching the name given will be returned, or `null` if that name does not exist. |
return | mixed | A string or array, depending on whether `$property` is specified. |
public handlers ( mixed $handlers = null ) : mixed | ||
$handlers | mixed | If `$handlers` is empty or no value is provided, the current list of handlers is returned. If `$handlers` is a string, the handler with the name matching the string will be returned, or null if one does not exist. If `$handlers` is an array, the handlers named in the array will be merged into the list of handlers in this rendering context, with the pre-existing handlers taking precedence over those newly added. |
return | mixed | Returns an array of handlers or a single handler reference, depending on the value of `$handlers`. |
public respondsTo ( string $method, boolean $internal = false ) : boolean | ||
$method | string | Name of the method. |
$internal | boolean | Provide `true` to perform check from inside the class/object. When `false` checks also for public visibility; defaults to `false`. |
return | boolean | Returns `true` if the method can be called, `false` otherwise. |
protected array $_autoConfig | ||
return | array |
protected array $_classes | ||
return | array |
protected array $_context | ||
return | array |
protected array $_data | ||
return | array |
protected array $_handlers | ||
return | array |
protected array $_helpers | ||
return | array |
protected array $_options | ||
return | array |
protected array $_strings | ||
return | array |
protected $_vars |
protected object $_view | ||
return | object |