PHPackages                             melisplatform/melis-cms-twig - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. melisplatform/melis-cms-twig

ActiveMelisplatform-module[Templating &amp; Views](/categories/templating)

melisplatform/melis-cms-twig
============================

Twig as an alternative templating engine in Melis CMS pages

v5.3.0(1y ago)18291OSL-3.0PHPPHP ^8.1|^8.3

Since Sep 30Pushed 1y ago6 watchersCompare

[ Source](https://github.com/melisplatform/melis-cms-twig)[ Packagist](https://packagist.org/packages/melisplatform/melis-cms-twig)[ Docs](https://github.com/melisplatform/melis-cms-twig)[ RSS](/packages/melisplatform-melis-cms-twig/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (21)Used By (1)

Melis CMS Twig
==============

[](#melis-cms-twig)

Extends Twig's functionalities to offer an alternative rendering strategy. This module is based on [ZendFramework's ZfcTwig](https://github.com/ZF-Commons/ZfcTwig).

Getting started
---------------

[](#getting-started)

These instructions will get you a copy of the project up and running on your machine.

### Installation

[](#installation)

Run the composer command:

```
composer require melisplatform/melis-cms-twig

```

Guides
------

[](#guides)

### Basic usage inside Melis Platform

[](#basic-usage-inside-melis-platform)

By default, Melis CMS Twig can be used to render a page inside Melis CMS by performing the following:

##### I. Base Template creation

[](#i-base-template-creation)

This base template will be extended by a child layout.

1. Inside your site's layout view folder, create a view file with a `twig` file extension:

    `..\view\layout\defaultTwigLayout.twig`

    This template must be registered in your site module's configuration:

    ```
    // inside module.config.php
    return [
        'view_manager' => [
          'template_map' => [
              'MyDemoSiteName/defaultTwigLayout' => __DIR__ . '/../view/layout/defaultLayout.twig',
          ]
        ]
    ];
    ```

    Possible contents of a base template can be seen in this sample: [defaultTwigLayout.twig](./etc/examples/defaultTwigLayout.twig)

##### II. Child Template creation

[](#ii-child-template-creation)

For this example, we will be creating a *"Home"* page.

1. Inside your site's view folder, create a new file:

    `..\view\my-demo-site-name\home\my-index.twig`

    Sample child templates: [index.twig](./etc/examples/index.twig) or [news-list.twig](./etc/examples/news-list.twig)
2. Inside Melis Platform, go to `MelisCms` &gt; `Site Tools` &gt; `Template manager`, and add a `New template`.

    - **Site:** My Demo Site Name
    - **Template type:** `Twig`
    - **Layout:** `defaultTwigLayout`
    - **Controller:** Home
    - **Action:** `myIndex`

    **Layout** shall be the base template's name as registered in your module configuration. In other words, *MyDemoSiteName/**defaultTwigLayout***.

    **Action** shall be the child template's comma-separated filename, transformed into Camel Case.

    Inside *Home Controller*, implement a method named `myIndexAction(...)`.

##### III. Twig a page

[](#iii-twig-a-page)

1. Inside Melis Platform, go to `MelisCms` &gt; `Site tree view`. Create a new page.
2. Set the page's `Template` to your child template from the previous step. Select `Draft` to save &amp; reload the Page.

    Note: To enable Twig rendering in front, enable Melis CMS Twig in in your site's `module.load.php`.

    ```
    return [
        ...
        'MelisCmsTwig',
        ...
    ];
    ```

### Using View Helpers

[](#using-view-helpers)

Inside your twig templates, Melis CMS Twig provides access to various [View Helpers](https://docs.zendframework.com/zend-view/helpers/intro/):

- **Laminas View Helpers** (*Layout, Doctype, etc.*)

    ```
    {# Generating Styles & JS in the  #}
    {{ headLink() }}
    {{ headScript() }}

    {# Using a layout variable #}
    {{ layout().myVar }}
    ```
- **Melis Helpers** (*MelisTag, MelisDragDropZone, etc.*)

    ```
    {# Displaying an editable text area (editable in back office only) #}
    {{ MelisTag(myPageId, "my-footer-title", "textarea", "My Cool Default Title") }}

    {# Setting a form's action via MelisLink, with configuration from Melis' SiteConfig helper #}
    ...

    ...
    ```
- **Melis Plugins** (*MelisCmsNewsListPlugin, MelisCmsNewsLatestPlugin, &amp; more*)

    ```
    {# Displaying a news list from MelisCmsNews, with parameters passed from controller #}
    {{ MelisCmsNewsListPlugin(listNewsParameters) }}
    ```

### Converting a Melis Plugin

[](#converting-a-melis-plugin)

To make use of Melis Plugins inside Twig templates, convert them as view helpers.

#### I. Helper creation

[](#i-helper-creation)

1. Create/Copy the helper class that extends Laminas's `AbstractHelper`.
2. Implement the `__invoke` method that it calls your plugin: `ServiceManager->get('ControllerPluginManager')->get('YourPlugin')`.
3. `return` the result of `ViewRenderer->render(YourPlugin)`.

#### II. Helper Factory creation

[](#ii-helper-factory-creation)

1. Create/Copy the helper factory class that implements Laminas's `FactoryInterface`
2. Implement the `createService` method that it instantiates the Helper from the previous step, passing all the needed parameters.

    ```
    return new YourPluginHelper($serviceManager, $var1, $var2);
    ```

#### III. Helper Registration

[](#iii-helper-registration)

The conversion process actually creates a [Twig function](https://twig.symfony.com/doc/2.x/advanced.html#id2) injected inside [Melis CMS Twig's Environment](./src/Factory/EnvironmentFactory.php) via ZF2's View Helper Manager. This is the reason why you need to register your plugin under the `view_helpers` key.

1. Under your site's configuration (`my-demo-site-name\config\module.config.php`), register your plugin's helper:

    ```
    ...
    'view_helpers' => [
        'factories' => [
            'YourPlugin' => 'MelisYourModule\View\Helper\Factory\YourPluginHelperFactory',
        ],
    ],
    'view_manager' => [...],
    ...
    ```

References
----------

[](#references)

These documentations mainly helped in understanding &amp; implementing the module:

- [Twig for Developers](https://twig.symfony.com/doc/2.x/api.html)
- [The MvcEvent](https://docs.zendframework.com/zend-mvc/mvc-event/)
- [The PhpRenderer](https://docs.zendframework.com/zend-view/php-renderer/)

Authors
-------

[](#authors)

- **Melis Technology** - [www.melistechnology.com](https://www.melistechnology.com/)

See also the list of [contributors](https://github.com/melisplatform/melis-cms-comments/contributors) who participated in this project.

License
-------

[](#license)

This project is licensed under the Melis Technology premium versions end user license agreement (EULA) - see the [LICENSE.md](LICENSE.md) file for details

###  Health Score

41

—

FairBetter than 88% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 50% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~144 days

Recently: every ~185 days

Total

13

Last Release

677d ago

Major Versions

v3.2.2 → v4.0.02020-08-17

v4.1.0 → v5.0.02022-06-21

PHP version history (4 changes)v3.1.0PHP ^7.0

v4.0.0PHP ^7.1.3|^7.2|^7.3

v5.0.0PHP ^7.3|^8.0

v5.1.0PHP ^8.1|^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/f8c3d1de854682cd37de2faa73a026b1c83b4b15500f352077581948c5d778ce?d=identicon)[melisplatform](/maintainers/melisplatform)

---

Top Contributors

[![ksuson](https://avatars.githubusercontent.com/u/31838758?v=4)](https://github.com/ksuson "ksuson (21 commits)")[![mariateresapomar](https://avatars.githubusercontent.com/u/85868605?v=4)](https://github.com/mariateresapomar "mariateresapomar (7 commits)")[![rbbrioso28](https://avatars.githubusercontent.com/u/9497212?v=4)](https://github.com/rbbrioso28 "rbbrioso28 (6 commits)")[![nicole-cayambas](https://avatars.githubusercontent.com/u/55810654?v=4)](https://github.com/nicole-cayambas "nicole-cayambas (4 commits)")[![sircxes](https://avatars.githubusercontent.com/u/21098160?v=4)](https://github.com/sircxes "sircxes (3 commits)")[![jpardillo](https://avatars.githubusercontent.com/u/40847547?v=4)](https://github.com/jpardillo "jpardillo (1 commits)")

---

Tags

twigcmsmodulezf2melis

### Embed Badge

![Health badge](/badges/melisplatform-melis-cms-twig/health.svg)

```
[![Health](https://phpackages.com/badges/melisplatform-melis-cms-twig/health.svg)](https://phpackages.com/packages/melisplatform-melis-cms-twig)
```

###  Alternatives

[zf-commons/zfc-twig

Zend Framework 2 Module that provides a Twig rendering strategy and extensions to render actions or trigger events from your templates

93576.6k7](/packages/zf-commons-zfc-twig)[melisplatform/melis-cms

Melis Platform CMS module

115.5k15](/packages/melisplatform-melis-cms)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
