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.

  1. create template in right place such as

    mybundle/resources/views/mycontroller/mytemplate.sh.twig 
  2. in scriptgenerator class

    // load template $template = $this->twig->loadtemplate('mybundle:mycontroller:mytemplate.sh.twig'); // render whole template $script = $template->render($parameters); 
  3. 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);          ...     } } 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -