Create HTML template with .pwr.html extension and make use in emails or whatever else!
composer require mykehowells/powerhtml
Include the composer autoloader
require __DIR__ . '/../vendor/autoload.php'
Getting started with a basic PowerHTML setup. The below code would output the processed PowerHTML template to the browser.
$powerHtml = new \PowerHTML\PowerHTML;
$template = ( $_SERVER[ 'REQUEST_URI'] == '/' ) ? null : ltrim( $_SERVER[ 'REQUEST_URI'], '/' );
$powerHtml->with( 'hello', 'hello world' )
->parse( $template );
$powerHtml->render();
If you're looking to store the parsed html into a variable, use store()
rather than render()
.
Default: /resources/templates
$options = [
'template_dir' => __DIR__ . '/public/templates'
];
$powerHtml = new \PowerHTML\PowerHTML( $options );
Stopping PHP evaluation will stop the curly braces from being parsed in your templates. For example: {{$my_var}} would be output as {{$my_var}}.
$options = [
'allow_php_eval' => false
];
$powerHtml = new \PowerHTML\PowerHTML( $options );