Skip to content

Boolean values in TagBuilder attribute and rendering result #1227

@billdagou

Description

@billdagou

Right now

$tagBuilder->addAttribute('attr', NULL); // ->getAttribute('attr') returns NULL, and ->render() results attr=""
$tagBuilder->addAttribute('attr', TRUE); // ->getAttribute('attr') returns 'attr', and ->render() results attr="attr"
$tagBuilder->addAttribute('attr', FALSE); // ->getAttribute('attr') returns NULL as the attribute has been removed, and ->render() results nothing.

I think it's a little messing. What I expected are:

$tagBuilder->addAttribute('attr', NULL); // removes the attribute, and ->render() results nothing
$tagBuilder->addAttribute('attr', TRUE); // ->getAttribute('attr') returns TRUE, and ->render() results attr or attr="attr"
$tagBuilder->addAttribute('attr', FALSE); // ->getAttribute('attr') returns FALSE, and ->render() results nothing or maybe attr="".

So for ->render(), considering the output for HTML5 and XHTML, I think it's better to introduce a new property and affect the final result according to its value.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions