Skip to content

Commit

Permalink
Allowing a html tag's attribute to be omitted from ouput by setting i…
Browse files Browse the repository at this point in the history
…ts value to null or false. Closes #316
  • Loading branch information
ADmad committed Feb 7, 2010
1 parent 843d3c7 commit 8c1c0e6
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 73 deletions.
12 changes: 8 additions & 4 deletions cake/libs/view/helper.php
Expand Up @@ -302,10 +302,12 @@ function clean($output) {
* 'escape' is a special option in that it controls the conversion of
* attributes to their html-entity encoded equivalents. Set to false to disable html-encoding.
*
* If value for any option key is set to `null` or `false`, that option will be excluded from output.
*
* @param array $options Array of options.
* @param array $exclude Array of options to be excluded, the options here will not be part of the return.
* @param string $insertBefore String to be inserted before options.
* @param string $insertAfter String to be inserted ater options.
* @param string $insertAfter String to be inserted after options.
* @return string Composed attributes.
* @access public
*/
Expand All @@ -322,7 +324,9 @@ function _parseAttributes($options, $exclude = null, $insertBefore = ' ', $inser
$attributes = array();

foreach ($keys as $index => $key) {
$attributes[] = $this->__formatAttribute($key, $values[$index], $escape);
if ($values[$index] !== false && $values[$index] !== null) {
$attributes[] = $this->__formatAttribute($key, $values[$index], $escape);
}
}
$out = implode(' ', $attributes);
} else {
Expand Down Expand Up @@ -711,7 +715,7 @@ function value($options = array(), $field = null, $key = 'value') {
}

/**
* Sets the defaults for an input tag. Will set the
* Sets the defaults for an input tag. Will set the
* name, value, and id attributes for an array of html attributes. Will also
* add a 'form-error' class if the field contains validation errors.
*
Expand All @@ -737,7 +741,7 @@ function _initInputField($field, $options = array()) {
/**
* Adds the given class to the element options
*
* @param array $options Array options/attributes to add a class to
* @param array $options Array options/attributes to add a class to
* @param string $class The classname being added.
* @param string $key the key to use for class.
* @return array Array of options with $key set.
Expand Down

0 comments on commit 8c1c0e6

Please sign in to comment.