# Store Twig-templates in database

**URL:** <https://discourse.slimframework.com/t/store-twig-templates-in-database/1113>\
**Category:** Questions\
**Created:** [February 1, 2017, 5:04pm UTC](https://discourse.slimframework.com/t/store-twig-templates-in-database/1113 "2017-02-01T17:04:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Keust](https://avatars.discourse-cdn.com/v4/letter/k/77aa72/32.png) [@Keust](https://discourse.slimframework.com/u/Keust)\
**Post date:** [February 1, 2017, 5:04pm UTC](https://discourse.slimframework.com/t/store-twig-templates-in-database/1113/1 "2017-02-01T17:04:29Z")

</div>

Hi Guys,

Last two days I am focussing how to use an database for storing .twig files (actually content). On the website there is an recipe but I don’t really get it.

Here is the link: [http://twig.sensiolabs.org/doc/2.x/recipes.html#using-a-database-to-store-templates](http://twig.sensiolabs.org/doc/2.x/recipes.html#using-a-database-to-store-templates)

This is the ‘current’ syntax:

```
return $this->view->render($response, 'pages/page.twig', [
            'pageData'	=> $pageData
]);

```

and I would like to replace ‘pages/page.twig’ for the array/data from the database. It does not work if I do it like this:

```
return $this->view->render($response, $template, [
            'pageData'	=> $pageData
]);

```

How can I solve this?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![SVL](https://avatars.discourse-cdn.com/v4/letter/s/848f3c/32.png) [@SVL](https://discourse.slimframework.com/u/SVL)\
**Post date:** [February 1, 2017, 8:09pm UTC](https://discourse.slimframework.com/t/store-twig-templates-in-database/1113/2 "2017-02-01T20:09:53Z")

</div>

You probally need to use the template\_from\_string method:  
[http://twig.sensiolabs.org/doc/2.x/recipes.html#loading-a-template-from-a-string](http://twig.sensiolabs.org/doc/2.x/recipes.html#loading-a-template-from-a-string)

Its what I use for templates stored in database.

---

<div class="post-metadata">

**Author:** ![Keust](https://avatars.discourse-cdn.com/v4/letter/k/77aa72/32.png) [@Keust](https://discourse.slimframework.com/u/Keust)\
**Post date:** [February 7, 2017, 8:29pm UTC](https://discourse.slimframework.com/t/store-twig-templates-in-database/1113/3 "2017-02-07T20:29:10Z")

</div>

Thanks SVL,

I will give it a try!
