Im trying to store Twig templates in a mysql database and extract them using Propel ORM 1.6
The mysql table is setup and has 3 demo templates/records. My Propel Schema is setup fine and have my classes to interact with the table.
if for example I use propel to extract the template primary key(1) like this:
$template = TemplateQuery::create->findPk(1);
and render the template like this:
$twig->render($template, array(
"name" => "testname",
"age" => "testage",
));
it errors with: "Catchable fatal error: Argument 1 passed to Twig_Environment::__construct() must implement interface Twig_LoaderInterface"
On this page (http://twig.sensiolabs.org/doc/recipes.html) of the Twig site there is an example if using twig templates from a database but ideally Id like to use Propel to get the template out.
Just to note Im not using any framework (e.g symfony) for the application. Im loading Twig and Propel via Composer into my site.
Can anyone point me in the right direction? Thank you for any advice you can offer.
I created a Twig String Loader like this:
$twig = new Twig_Environment(new Twig_Loader_String());
then I rendered the template like this (with $template->getHtml() being my getter to the field in the db):
$code = $twig->render($template->getHtml(), array(
"name" => "testname",
"age" => "testage",
));
This might not be the correct way to do it but it seems to work. Id still be interested to see what other people have done =)