cable8mm/stub-template

The package is not a template engine, but you can use it like one to create stub files when needed.

v1.0.0 2025-02-11 08:42 UTC

This package is auto-updated.

Last update: 2025-02-11 13:59:13 UTC


README

Coding Style Actions Run Tests Actions Latest Version on Packagist Packagist Dependency Version Total Downloads Packagist Stars

The package is not a template engine, but you can use it like one to create stub files when needed.

It needs to be used with Twig template syntax.

Installation

You can install the package via composer:

composer require cable8mm/stub-template

Usage

$stub = Stub::of(__DIR__.'/stubs/sample.stub',
  [
    'title' => 'Home Page',
    'colors' => ['red', 'blue', 'green'],
  ]
)->render()

or

$stub = Stub::of('stubs/sample.stub',
  [
    'title' => 'Home Page',
    'colors' => ['red', 'blue', 'green'],
  ],
  __DIR__
)->render()

stubs/sample.stub :

{{ title }} - <?php echo date('Y-m-d') ?>

<h1>Home</h1>
<p>Welcome to the home page, list of colors:</p>
<ul>
{% for color in colors %}
    <li>{{ color }}</li>
{% endfor %}
</ul>

Then,

Home Page - <?php echo date('Y-m-d') ?>

<h1>Home</h1>
<p>Welcome to the home page, list of colors:</p>
<ul>
    <li>red</li>
    <li>blue</li>
    <li>green</li>
</ul>

It make sure that php codes have NOT been executed.

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email cable8mm@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

PHP Package Boilerplate

This package was generated using the PHP Package Boilerplate by Beyond Code.