doulangpeng3933 2017-03-04 10:47
浏览 54
已采纳

如何使用twig渲染来制作文件?

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?

  • 写回答

1条回答 默认 最新

  • douzao2992 2017-03-04 11:00
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?