symfony - Twig 从 Yaml 文件写入

标签 symfony twig yaml

我有这个问题: 我的 yaml 文件:

locale: en 
 codes:
    button.cancel: Cancel
    button.accept: Accept
    radio.male: Male
    radio.female: Female

我需要将所有 yaml 文件写入我的页面

Controller Action :

/**
     * @Route("/read/")
     * @Template()
     */
    public function readAction()
    {
        $yaml = new Parser();
        $file = $yaml->parse(file_get_contents(getcwd() .'/file.yml'));
        return $this->render('AnyoneYamlGeneratorBundle:GenerateController:read.html.twig', array(
            'files' => $file,
            ));
    }

我的 Twig 文件:

{% for file in files %}
{% for key,value in file  %}
{{key}}: {{value}}<br>
{% endfor %}
{% endfor %}

我的浏览器的答案是

button.cancel: Cancel
button.accept: Accept
radio.male: Male
radio.female: Female

我需要我所有的 yaml 文件 感谢帮助

最佳答案

好的,我解决了这是 Twig 文件:

locale: {{files["locale"]}}<br>
codes:<br>
 {% for file in files %}
  {% for code,value in file  %}
  &nbsp;{{code}}: {{value}}<br>
  {% endfor %}
 {% endfor %}

关于symfony - Twig 从 Yaml 文件写入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23983992/

相关文章:

Symfony ChoiceType 启用或禁用 TextType

arrays - Twig:追加到数组/对象内的数组

symfony - Twig:允许 HTML,但转义脚本

windows - Windows 中 Kubernetes .yaml 中 PersistentVolume 的路径

php - 如何控制 Symfony 的 RepeatedType 验证序列

php - 无法使用 symfony 和 doctrine 及其关联对象或表保存到 postgresql 中?

php - YAML 或 serialize() 在 MySQL 中存储数据

ruby-on-rails - 如何将 YAML 放入 YAML 文档中

php - 在 Symfony 文件对象中加载 'php://temp' 或 'php://memory' 文件