Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twig write from Yaml file

Tags:

yaml

twig

symfony

I have this problem: My yaml file:

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

I need to write all of yaml file into my page

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

my twig file:

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

answer of my browser is

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

and i need all of my yaml file Thanks for help

like image 541
Franky238 Avatar asked Apr 17 '26 18:04

Franky238


1 Answers

OK i solved this is twig file:

locale: {{files["locale"]}}<br>
codes:<br>
 {% for file in files %}
  {% for code,value in file  %}
  &nbsp;{{code}}: {{value}}<br>
  {% endfor %}
 {% endfor %}
like image 158
Franky238 Avatar answered Apr 23 '26 08:04

Franky238



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!