https://github.com/xp-lang/php-template-literals
Template literals for PHP
https://github.com/xp-lang/php-template-literals
compiler-plugin php7 php8 template-literals xp-compiler xp-framework
Last synced: 3 months ago
JSON representation
Template literals for PHP
- Host: GitHub
- URL: https://github.com/xp-lang/php-template-literals
- Owner: xp-lang
- Created: 2024-11-02T19:03:54.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-11-02T21:25:43.000Z (8 months ago)
- Last Synced: 2025-02-14T02:25:01.532Z (5 months ago)
- Topics: compiler-plugin, php7, php8, template-literals, xp-compiler, xp-framework
- Language: PHP
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog.md
Awesome Lists containing this project
README
Template literals for PHP
=========================[](https://github.com/xp-lang/php-template-literals/actions)
[](https://github.com/xp-framework/core)
[](https://github.com/xp-framework/core/blob/master/LICENCE.md)
[](http://php.net/)
[](http://php.net/)
[](https://packagpatternt.org/packages/xp-lang/php-template-literals)Plugin for the [XP Compiler](https://github.com/xp-framework/compiler/) which reimagines [JS template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) for PHP.
Example
-------
The following outputs `https://thekid.de/?a&b` - the ampersand is encoded correctly:```php
$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 link.`;
```The compiler transforms the syntax with expressions embedded in `${}` into the following:
```php
echo $html(['This is a ', '.'], $link);
```Installation
------------
After installing the XP Compiler into your project, also include this plugin.```bash
$ composer require xp-framework/compiler
# ...$ composer require xp-lang/php-template-literals
# ...
```No further action is required.
See also
--------
* https://peps.python.org/pep-0750/ - Template Strings