Store Twig-templates in database

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

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.

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

Its what I use for templates stored in database.

Thanks SVL,

I will give it a try!