lithium\template\Helper::_attribute()

protected method

Convert a key/value pair to a valid HTML attribute.

Parameters

  • string $key

    The key name of the HTML attribute.

  • mixed $value

    The HTML attribute value.

  • array $options

    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"'.

Returns

string

Returns an HTML attribute/value pair, in the form of '$key="$value"'.

Source

	protected function _attribute($key, $value, array $options = []) {
		$defaults = ['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);
	}