Plugin for the XP Compiler which reimagines JS template literals for PHP.
The following outputs https://thekid.de/?a&b
- the ampersand is encoded correctly:
$html= function($strings, ... $arguments) {
$r= '';
foreach ($strings as $i => $string) {
$r.= $string.htmlspecialchars($arguments[$i] ?? '');
}
return $r;
};
$link= 'https://thekid.de/?a&b';
echo $html`This is a <a href="${$link}">link</a>.`;
The compiler transforms the syntax with expressions embedded in ${}
into the following:
echo $html(['This is a ', '.'], $link);
After installing the XP Compiler into your project, also include this plugin.
$ composer require xp-framework/compiler
# ...
$ composer require xp-lang/php-template-literals
# ...
No further action is required.
- https://peps.python.org/pep-0750/ - Template Strings