I would like to use twig to make js file.
These are what I want to do.
web/base.js
// this is my base file
alert("this file is created by " + "{{var}}");
Then in my Command /src/Acme/TopBundle/Command/genFileCommand.php
class genFileCommand extends ContainerAwareCommand
{
protected function execute(InputInterface $input, OutputInterface $output){
$var = 'whitebear';
//then some how pass the this value to twig and make file here
}
}
Finally, I want make this file be created.
/web/gen/generated.js
// this is my base file
alert("this file is created by " + "whitebear");
It might be a irregular way to use twig in this way though, twig is very simple and good rendering system.
If I can do this way, code is more readable and good for maintenance.
Is it possible?
The quickest way should be to place your javascript base file inside the view folder from Twig
, then render the base template with you vars and save the output with file_put_contents
to the gen
folder.