【问题标题】:Twig write from Yaml file从 Yaml 文件中写入的 Twig
【发布时间】:2014-06-01 20:08:58
【问题描述】:

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

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

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

控制器动作:

/**
     * @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,
            ));
    }

我的树枝文件:

{% 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 文件 感谢您的帮助

【问题讨论】:

  • 我需要我所有的 yaml 文件 我看到文件的所有内容都已经显示出来了。有什么问题?
  • 缺少语言环境:en en:
  • locale 没有 key,value,因为它不是数组。我认为这就是它不显示的原因。
  • 已解决的答案已关闭

标签: symfony twig yaml


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-23
    • 1970-01-01
    • 1970-01-01
    • 2016-10-05
    • 2015-05-11
    • 2018-01-08
    • 1970-01-01
    相关资源
    最近更新 更多