Nette\Utils\Html: special way to access classes?

4 years ago

Member | 406


I was first considering writing pull request, but I decided to ask community instead.

In code I often get a Html object and I want to add class or check if it has some class. I think, that best way to do this is to let Html object have a public array of strings (classes) or methods (not magical) to add, remove and check classes.

Example usage:

$html = Html::el("div");

$html->addClasses(["class1", "class2"]);
$html->getClasses(); // array("class1", "class2")
$html->hasClass("class1"); // TRUE
$html->hasClass("class3"); // FALSE
$html->hasClass("class3"); // TRUE
$html->getClasses(); // array("class1", "class3")

echo $html; // <div class="class1 class3"></div>

What do you think about it?

3 years ago

Member | 3

Hello, I think that this is good idea.