lithium\template\Helper::_attributes PHP Method

_attributes() protected method

Converts a set of parameters to HTML attributes into a string.
See also: lithium\template\view\Renderer::__call()
protected _attributes ( array | string $params, string $method = null, array $options = [] ) : string
$params array | string The parameters where key is the attribute name and the value the attribute value. When string will simply prepend with the prepend-string (by default `' '`) unless $params is falsey in which case an empty string is returned. This alternative syntax is used by the method internally.
$method string When used as a context handler, the method the handler was called for I.e. `'wrap'`. Currently not used by the method.
$options array Available options are: - `'escape'` _boolean_: Indicates whether the output should be HTML-escaped. Defaults to `true`. - `'prepend'` _string_: String to prepend to each attribute pair. and the final result. Defaults to `' '`. - `'append'` _string_: String to append to result. Defaults to `''`.
return string Attribute string.
    protected function _attributes($params, $method = null, array $options = array())
    {
        $defaults = array('escape' => true, 'prepend' => ' ', 'append' => '');
        $options += $defaults;
        $result = array();
        if (!is_array($params)) {
            return !$params ? '' : $options['prepend'] . $params;
        }
        foreach ($params as $key => $value) {
            if ($next = $this->_attribute($key, $value, $options)) {
                $result[] = $next;
            }
        }
        return $result ? $options['prepend'] . implode(' ', $result) . $options['append'] : '';
    }