php - Creating a file text with symfony2 and twig -
i generate file text symfony2 controller twig.
like normal html templating plain text, , save file somewhere.
is possible ?
finally got it.
i wanted generate bash script.
create template in right place such as
mybundle/resources/views/mycontroller/mytemplate.sh.twig
in scriptgenerator class
// load template $template = $this->twig->loadtemplate('mybundle:mycontroller:mytemplate.sh.twig'); // render whole template $script = $template->render($parameters);
where want use it, place code.
namespace myproject\mybundle\controller; use symfony\bundle\frameworkbundle\controller\controller; use myproject\mybundle\generator\scriptgenerator; class mycontroller extends controller { public function myaction() { $twig = $this->get('twig'); $generator = new scriptgenerator($twig); $parameters = array( 'a parameter' => "whatever" ); $script = $generator->setscript($parameters); file_put_contents('whereyouwant',$script); ... } }