lithium\template\Helper::attributes()
Converts a set of parameters to HTML attributes into a string.
Parameters
-
array|string
$paramsThe 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. -
string
$methodWhen used as a context handler, the method the handler was called for I.e.
'wrap'. Currently not used by the method. -
array
$optionsAvailable options are:
'escape'boolean: Indicates whether the output should be HTML-escaped. Defaults totrue.'prepend'string: String to prepend to each attribute pair and the final result. Defaults to' '.'append'string: String to append to result. Defaults to''.
Returns
stringAttribute string.
Source
public function attributes($params, $method = null, array $options = []) {
$defaults = ['escape' => true, 'prepend' => ' ', 'append' => ''];
$options += $defaults;
$result = [];
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'] : '';
}