php-micro-template

A minimalistic templating engine for PHP

MIT License

Downloads
61.3K
Stars
14
Committers
2

Bot releases are hidden (Show)

php-micro-template - callbacks and PHP methods Latest Release

Published by wol-soft about 1 year ago

Allow to assign callbacks to the template (prior versions were only capable to call methods on assigned objects) as well as the possibility to directly call PHP methods from the template.

php-micro-template - Allow constant values

Published by wol-soft about 1 year ago

The rendering now supports resolving constant values (integer numbers, strings in single quotes and booleans [true, false]):

<html>
    <p>Products: {{ viewHelper.getTitle('mySite.title', true) }}</p>
    <!-- TODO: fill with dynamic content -->
    <span>Visitors: {{ 3000 }}</span>
</html>
php-micro-template -

Published by wol-soft almost 3 years ago

php-micro-template - Access to public object properties

Published by wol-soft almost 3 years ago

Allows to access public object properties from a template:

$person = new stdClass();
$person->name = 'Hans';

$render->renderTemplateString(
    '{{ person.name }}',
    [
        'person' => $person,
    ]
);

Bugfixes: #5

php-micro-template - Undefined variable error handler

Published by wol-soft almost 3 years ago

Allow attaching an error handler to handle undefined variable errors instead of triggering an UndefinedSymbolException:

$render->onResolveError(function (string $var): string {
    return 'Undefined';
});

// will result in "Person name: Undefined"
$result = $render->renderTemplateString('Person name: {{ name }}');
php-micro-template - Resolve nested variables

Published by wol-soft almost 3 years ago

Provided data may be a nested array which can be resolved in the template:

$render->renderTemplateString(
    '{{ render.productRender.renderProductName(product.details.name) }}',
    [
        'product' => [
            'details' => [
                'name' => 'MyProduct',
            ],
        ],
        'render' => [
            'productRender' => new ProductRender(),
        ]
    ]
);
php-micro-template - Key-Value Pairs

Published by wol-soft almost 4 years ago

Loops now support the usage of key value pairs:

{% foreach products as bestSellerNumber, product %}
    <b>Bestseller Nr. {{ bestSellerNumber }}:</b>{{ product.getTitle() }}<br/>
{% endforeach %}

Variable names may contain underscores:

{{ my_variable_will_be_resolved }}
php-micro-template -

Published by wol-soft over 4 years ago

Added minor performance tweaks

php-micro-template - 1.3.1

Published by wol-soft about 5 years ago

Bugfix: if null is provided as a value to the template the corresponding key is recognized as undefined

php-micro-template - 1.3.0

Published by wol-soft over 6 years ago

Add not keyword to conditional statements

php-micro-template - 1.2.1

Published by wol-soft over 6 years ago

Fix successive loops

php-micro-template - 1.2.0

Published by wol-soft over 6 years ago

Add else to conditional statements

php-micro-template - 1.1.0

Published by wol-soft over 6 years ago

  • Function calls can have parameters, for example a ViewHelper-Object with advanced logic can be used
  • The templating syntax is now whitespace tolerant.
php-micro-template - 1.0.0

Published by wol-soft over 6 years ago

Features

  • Replace variables inside a template
  • Iterate over an array or iterable object
  • Conditional sections
  • Pass objects and call functions on the objects