lithium\template\Helper::_attribute PHP Method

_attribute() protected method

Convert a key/value pair to a valid HTML attribute.
protected _attribute ( string $key, mixed $value, array $options = [] ) : string
$key string The key name of the HTML attribute.
$value mixed The HTML attribute value.
$options array The options used when converting the key/value pair to attributes: - `'escape'` _boolean_: Indicates whether `$key` and `$value` should be HTML-escaped. Defaults to `true`. - `'format'` _string_: The format string. Defaults to `'%s="%s"'`.
return string Returns an HTML attribute/value pair, in the form of `'$key="$value"'`.
    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);
    }