jhse-labs/mezzio-twig-viewhelper

Bridges laminas view helpers to the twig environment when running a mezzio application

1.1.0 2024-04-22 20:44 UTC

This package is not auto-updated.

Last update: 2024-04-22 20:45:57 UTC


README

Within mezzio applications, this module bridges the classic laminas view helpers to the twig environment enabled by mezzio-twigrenderer. You can use all laminas view helpers (e.g. for rendering laminas-form components) seamlessly from you twig templates.

This is inspired by kokspflanze/zfc-twig, the module that achieved this functionality for laminas-mvc.

Installation

Install the library using composer:

composer require jhse-labs/mezzio-twig-viewhelper

Enable the module in config.php:

<?php

$aggregator = new ConfigAggregator([
    \JhseLabs\MezzioTwigViewHelper\ConfigProvider::class,
    ...

The laminas view helper support is added to your Twig\Environment instance automatically via registering a delegator factory.

Usage

Within your Twig templates you can now call all your laminas view helpers:

<head>
    {{ headTitle('Login Page') }}
</head>
<body>
    {{ form(loginForm) }}
</body>

Since version 1.1.0 it is possible to call laminas view helpers with named arguments:

{{ form(form=loginForm, method='POST') }}