lithium\template\Helper::_attribute()
Convert a key/value pair to a valid HTML attribute.
Parameters
-
string
$keyThe key name of the HTML attribute.
-
mixed
$valueThe HTML attribute value.
-
array
$optionsThe options used when converting the key/value pair to attributes:
'escape'boolean: Indicates whether$keyand$valueshould be HTML-escaped. Defaults totrue.'format'string: The format string. Defaults to'%s="%s"'.
Returns
stringReturns an HTML attribute/value pair, in the form of '$key="$value"'.
Source
protected function _attribute($key, $value, array $options = array()) {
$defaults = array('escape' => true, 'format' => '%s="%s"');
$options += $defaults;
if (in_array($key, $this->_minimized)) {
$isMini = ($value === 1 || $value === true || $value === $key);
if (!($value = $isMini ? $key : $value)) {
return null;
}
}
$value = (string) $value;
if ($options['escape']) {
return sprintf($options['format'], $this->escape($key), $this->escape($value));
}
return sprintf($options['format'], $key, $value);
}