PhpGt / DomTemplate

Bind dynamic data to reusable HTML components.
https://www.php.gt/domtemplate
MIT License
17 stars 4 forks source link

Allow passing context node as a query selector string #454

Open g105b opened 1 year ago

g105b commented 1 year ago

The $context parameter of bind functions would be enhanced if it would also accept a string: the query selector of the context node. That would mean you wouldn't necessarily need to import the whole HTMLDocument in a go function, for example.

function go(DocumentBinder $binder):void {
    $binder->bindList(["one", "two", "three"], "example-element");
}

rather than:

function go(DocumentBinder $binder, HTMLDocument $document):void {
    $binder->bindList(["one", "two", "three"], $document->querySelector("example-element"));
}