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

Notice: This thread is very old.
greeny
Member | 405
+
0
-

Hi,

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->addClasses(["class3"]);
$html->hasClass("class3"); // TRUE
$html->removeClass("class2");
$html->getClasses(); // array("class1", "class3")

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

What do you think about it?

homolka
Member | 3
+
0
-

Hello, I think that this is good idea.