sabujdas94/html-template-parser

A secure Twig-based HTML template parser for user-provided templates input.

v1.0.3 2024-12-06 07:37 UTC

This package is auto-updated.

Last update: 2025-09-06 09:48:48 UTC


README

You can find usage examples in the examples/ directory.

Basic Example

require 'path-to-your-package/vendor/autoload.php';

use SecureTemplateParser\SecureTemplateParser;

$parser = new SecureTemplateParser();

$template = <<<EOT
Hi {{ user.name }}

{% if user.age > 18 %}
You're eligible for adult benefits.
{% else %}
You're still a minor.
{% endif %}
EOT;

$data = [
    'user' => [
        'name' => 'John Doe',
        'age' => 25,
    ],
];

echo $parser->render($template, $data);

## License

This package is open-source software licensed under the [MIT License](LICENSE).