簡體   English   中英

樹枝從Yaml文件寫入

[英]Twig write from Yaml file

我有這個問題:我的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文件謝謝您的幫助

OK,我解決了這是樹枝文件:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM