Open wbijker opened 9 months ago
With the use of a union variadic type we can combine attributes and nodes to give us a clear and concise syntax .
class Attribute {}
class Tag {}
function _class(string $value): Attribute {
return new Attribute();
}
/**
* @param (Attribute|Tag) ...$args
* @return Tag
*/
function div(...$args): Tag {
return new Tag('div', ...$args);
}
function text(string $value): Tag {
return new Tag();
}
$node = div(_class("mx-10"),
div(_class("p-2"),
text("some text")
)
);
class is almost always used. Make it a optional first argument
/**
* @param string|null $class
* @param (Attribute|Tag) ...$args
* @return Tag
*/
function div(?string $class = null,, ...$args): Tag {
return new Tag('div', ...$args);
}
$node = div("mx-10",
div("p-2",
text("some text")
)
);
I don't like custom templating languages. Primary for its lack of type safety. And off course the extra compilation step.
What about a strongly typed render function? Just like we have in almost all functional languages.