# Example for using Twig in Laminas?

**URL:** <https://discourse.laminas.dev/t/example-for-using-twig-in-laminas/2066>\
**Category:** Components & MVC\
**Tags:** twig, laminas-mvc\
**Created:** [January 24, 2021, 5:34pm UTC](https://discourse.laminas.dev/t/example-for-using-twig-in-laminas/2066 "2021-01-24T17:34:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kim736](https://avatars.discourse-cdn.com/v4/letter/k/7ea924/32.png) [@Kim736](https://discourse.laminas.dev/u/Kim736)\
**Post date:** [January 24, 2021, 5:34pm UTC](https://discourse.laminas.dev/t/example-for-using-twig-in-laminas/2066/1 "2021-01-24T17:34:04Z")

</div>

Using Laminas as “laminas/laminas-mvc-skeleton”, i would like to use twig as default template. I installes it:

```
"require": {
        "php": "^7.3",
        "laminas/laminas-component-installer": "^1.0 || ^2.1",
        "laminas/laminas-development-mode": "^3.2",
        "laminas/laminas-mvc": "^3.1.1",
        "laminas/laminas-cache": "^2.9.0",
        "laminas/laminas-db": "^2.10.0",
        "laminas/laminas-json": "^3.1.2",
        "laminas/laminas-log": "^2.11",
        "laminas/laminas-mvc-i18n": "^1.1.1",
        "laminas/laminas-psr7bridge": "^1.2.0",
        "laminas/laminas-session": "^2.9.1",
        "mezzio/mezzio-twigrenderer": "^2.6"
    },

```

but after that, the docs leave me allone, how to implement and use the twig templates correctly in my controllers:

```
class IndexController extends AbstractActionController {

    public function indexAction() {
		
        $view = new ViewModel(array(
			"message" => "Hello world",
		));
        
        $view->setTemplate("path/to/index.twig");
        
        return $view;
        
    }
    
}

```

The twig-temaplte file is loaded, but is displayed “as it is”, no twig handling.

Do somebody pls have an example of how to use twig within the controller function ?

Thanks in advance,  
kim

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [January 26, 2021, 9:42am UTC](https://discourse.laminas.dev/t/example-for-using-twig-in-laminas/2066/2 "2021-01-26T09:42:31Z")

</div>

Hello and welcome to our forums! 😃

> [@Kim736](#):
>
> Using Laminas as “laminas/laminas-mvc-skeleton”…

You are mixing two different libraries that have different concepts for building applications.

laminas-mvc follows the typical software design pattern “model–view–controller” and with Mezzio you can create middleware applications, using the [PSR-7 (HTTP Messages)](https://www.php-fig.org/psr/psr-7/) and [PSR-15 (HTTP Request Handlers)](https://www.php-fig.org/psr/psr-15/) specifications.

For your installation this means you can not use the package “mezzio-twigrenderer” in a laminas-mvc based application. But a laminas-mvc application can be extended via modules and for the support of Twig you can use:

> **[GitHub - OxCom/zf3-twig: ZendTwig is a module that integrates the Twig...](https://github.com/OxCom/zf3-twig)**
>
> ZendTwig is a module that integrates the Twig template engine with Laminas. - GitHub - OxCom/zf3-twig: ZendTwig is a module that integrates the Twig template engine with Laminas.

(Don’t worry about the name, the module also runs with the newer versions of laminas-mvc.)
