PhpGt / DomTemplate

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

Allow bind functions' context to be a string #485

Closed g105b closed 6 months ago

g105b commented 9 months ago

Currently there is an optional $context parameter to bind functions. Whenever I use this parameter, I always do $binder->bindList($listOfStuff, $document->querySelector("select[name='thing']"); to bind a list of stuff into a select element (for example).

It would be nicer if I could pass just the selector into the context, and for the binder to do the querySelector for me. This is not only shorter to type, but it also means I won't have to import the HTMLDocument each time I want this functionality.

Proposed new style:

function go(Binder $binder):void {
  $binder->bindList(["one", "two", "three"], "[name='thing']");
}