Simple curly braces micro templating

0.2.1 2017-05-29 09:01 UTC

This package is auto-updated.

Last update: 2024-10-26 02:24:28 UTC


README

SensioLabsInsight

Simple curly braces micro templating.

Install

composer require schnittstabil/curty

Usage

// Context (variable lookup table)
$ctx = [
    'user' => [
        'login' => 'curt',
        'phone' => [
            'internal' => 1337,
        ],
    ],
    'unicorn' => '{user.login}: {user.phone.internal}',
    'lazy' => function ($ctx) : string {
        return date('z').' {unicorn}';
    },
];

/*
 * Simple rendering
 */
use Schnittstabil\Curty;

echo Curty\render('{user.login}', $ctx); // => 'curt'
echo Curty\render('{unicorn}', $ctx);    // => '{user.login}: {user.phone.internal}'
echo Curty\render('{lazy}', $ctx);       // => '42 {unicorn}'

/*
 * Fixed-point rendering
 */
use function Schnittstabil\curty;

echo curty('{user.login}', $ctx); // => 'curt'
echo curty('{unicorn}', $ctx);    // => 'curt: 1337'
echo curty('{lazy}', $ctx);       // => '42 curt: 1337'

License

MIT © schnittstabil