Skip to content

xp-lang/php-template-literals

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Template literals for PHP

Build status on GitHub XP Framework Module BSD Licence Requires PHP 7.4+ Supports PHP 8.0+ Latest Stable Version

Plugin for the XP Compiler which reimagines JS template literals for PHP.

Example

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);

Installation

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.

See also

Releases

No releases published

Languages