DomTemplate

Bind dynamic data to reusable HTML components.

MIT License

Downloads
6.3K
Stars
17
Committers
5

Bot releases are visible (Hide)

DomTemplate - April 2024 release Latest Release

Published by g105b 6 months ago

What's Changed

Full Changelog: https://github.com/PhpGt/DomTemplate/compare/v3.4.0...v3.4.1

DomTemplate - Remove elements with bind attribute

Published by g105b 9 months ago

What's Changed

Full Changelog: https://github.com/PhpGt/DomTemplate/compare/v3.3.0...v3.4.0

DomTemplate - IteratorAggregate objects

Published by g105b 12 months ago

What's Changed

Full Changelog: https://github.com/PhpGt/DomTemplate/compare/v3.2.3...v3.3.0

DomTemplate - Type check - ReflectionNamedType

Published by g105b about 1 year ago

What's Changed

Full Changelog: https://github.com/PhpGt/DomTemplate/compare/v3.2.2...v3.2.3

DomTemplate - Remove data-elements as last operation

Published by g105b over 1 year ago

DomTemplate - Introduce data-element

Published by g105b over 1 year ago

This release introduces a helper attribute, data-element, which can be used to remove unbound elements from the document. Documentation here: https://github.com/PhpGt/DomTemplate/wiki/automatically-remove-unbound-elements

What's Changed

Full Changelog: https://github.com/PhpGt/DomTemplate/compare/v3.2.0...v3.2.1

DomTemplate - March 2023 minor release

Published by g105b over 1 year ago

What's Changed

Full Changelog: https://github.com/PhpGt/DomTemplate/compare/v3.1.5...v3.2.0

DomTemplate - January 2023 release

Published by g105b almost 2 years ago

What's Changed

Full Changelog: https://github.com/PhpGt/DomTemplate/compare/v3.1.4...v3.1.6

DomTemplate - v3 December 2022 release

Published by g105b almost 2 years ago

What's Changed

Full Changelog: https://github.com/PhpGt/DomTemplate/compare/v3.1.4...v3.1.5

DomTemplate - Upgrade dom requirement and loosen version range

Published by g105b about 2 years ago

This minor patch release bumps the Dom version, but loosens the semver range as defined by Composer. This will allow future minor releases of Dom to be included by DomTempalte without having to make a new release.

DomTemplate - ReadOnly property bugfix

Published by g105b over 2 years ago

What's Changed

New Contributors

Full Changelog: https://github.com/PhpGt/DomTemplate/compare/v3.1.2...v3.1.3

DomTemplate - Stabalise dependencies

Published by g105b over 2 years ago

A minor patch release to stabalise the dependency on php.gt/dom

DomTemplate - Temporary fix for PHP XML bug 81506

Published by g105b over 2 years ago

The bug in PHP's XML implementation deallocates the Text node from memory, even though it might be referenced later. This patch release includes a number of hacky fixes to resolve this downstream, which is a good solution before the PHP bug is fixed.

DomTemplate - Support for Read Only properties

Published by g105b over 2 years ago

What's changed:

In this minor release, classes of the application can now take advantage of PHP 8.1's new readonly keyword. Any properties that are marked as public readonly will be exposed as Bindable values now, removing a lot of boilerplate code on Model classes.

Example:

// Model class:
class PersonModel {
	public function __construct(
		public readonly string $id,
		public readonly string $name,
		public readonly int $age,
	) {}

	#[BindGetter]
	public function getAgeStatus():string {
		return $this->age >= 18
			? "adult"
			: "minor";
	}
}
// Page code:
function go(Input $input, DocumentBinder $binder, PersonRepository $personRepo):void {
	$binder->bindData($personRepo->getById($input->getString("id"));
}
<!-- Page view -->
<div class="user-profile">
	<h1 data-bind:text="name">User name<h1>
	<img src="/asset/img/user-profile/{{id}}.jpg" alt="{{name}}'s user profile" />
	<p>This user is marked as <span data-bind:text="ageStatus">Age Status</span></p>
</div>
DomTemplate - Native DOMDocument extension

Published by g105b over 2 years ago

The major change in this release is the switch to phpgt/dom v4, which now extends the native DOMDocument rather than using a Facade pattern. This greatly improves efficiency.

Changes in functionality also include:

  • cyclic recursion in partials is now handled
  • binding of data only occurs once per bind, unless the data-rebind attribute is present

Full Changelog: https://github.com/PhpGt/DomTemplate/compare/v2.2.4...v3.0.0

DomTemplate - Minor bugfixes & PHP 8.1 compatibility

Published by g105b over 2 years ago

fix: bind multiple attribute placeholders https://github.com/PhpGt/DomTemplate/pull/327

Example: <a href="/path/to/{{project}}/with/{{another}}/attribute/placeholder"> - any attribute can now contain multiple placeholders.

290 default placeholder https://github.com/PhpGt/DomTemplate/pull/328

Example: Hello, {{name ?? you}}!

fix: resolve deprecation notices https://github.com/PhpGt/DomTemplate/pull/329

PHP 9 will introduce a lot more strict typing, and 8.1 has started emitting deprecation notices. These have all been addressed in this release.

fix: insert template before correct element https://github.com/PhpGt/DomTemplate/pull/330

When template elements have more than one similar siblings, the correct next sibling is remembered, and the template element is inserted in the correct position.

Identify template parents when there are ambiguous XPath selectors https://github.com/PhpGt/DomTemplate/pull/337

Similarly to above, when two or more template elements have similarly-addressed parents, the template element is now always added to the correct one.

DomTemplate - Move responsibility of HTMLSelectElement::$value to PhpGt/Dom

Published by g105b over 2 years ago

The functionality added in the previous release has been moved to be implemented and tested within PHP.Gt/Dom so other projects can take advantage of the functionality, without using DomTemplate.

DomTemplate - Select binding by value

Published by g105b over 2 years ago

Along with some dependency upgrades, the extra functionality introduced in this release allows an HTMLSelectElement to have its value bound, so the relevant HTMLOptionElement is selected. This works using the value attribute whether or not the option has a value - without a value, the textContent of the option will be used.

DomTemplate - Binding tweaks

Published by g105b almost 3 years ago

In this minor patch release, there are two improvements:

  • Table bind attributes like data-template-key are removed during the cleanBindAttributes() call.
  • Strings that contain names of inbuilt PHP functions are not treated as "callable" types when binding values.
DomTemplate - Improvements to table binding with existing content

Published by g105b almost 3 years ago

When a <table> element already exists on the page, it would be useful to utilise the contents of the table, retaining parts of it as a template when binding.

This minor release introduces improvements to help this case:

  • Existing <th> elements that don't match any bound data are preserved.
  • Bound data that doesn't match any existing headers is discarded.
  • Importantly: existing <tr> elements can be marked with data-template to add pre-templated row shapes for advanced designs.