credy/yii2-twig-stringrenderer

Twig string renderer for Yii2 Framework

1.0.0 2024-07-11 15:33 UTC

This package is auto-updated.

Last update: 2024-10-11 13:08:42 UTC


README

Installation

The preferred way to install this extension is through composer.

Run

composer require --prefer-dist credy/yii2-twig-stringrenderer

Usage

Either use directly in your class:

use credy\twig\StringRenderer;

class YourClassName extends BaseObject
{
    public function yourMethod()
    {
        $renderer = new StringRenderer();

        $renderer->render('your twig {{ template_name }}', [
            'template_name' => 'template'
        ]);
    }
}

or put following snippet into your config:

return [
    'components' => [
        'twigRenderer' => [
            'class' => credy\twig\StringRenderer::class,
        ]
    ]
];

And use the component in your class:

class YourClassName extends BaseObject
{
    public function yourMethod()
    {
        Yii::$app->twigRenderer->render('your twig {{ template_name }}', [
            'template_name' => 'template'
        ]);
    }
}