To abstract some vars I would like to read a yaml file to get some vars into my twig files.

Is this possible?

Thank you

Comments

Jeff Burnz’s picture

You can from preprocess and set it into variables for the template.

If they're config yml you can get it directly from configuration, but if they're not you have to parse the yml file and get key/values from that, e.g. something along the lines of:

use Symfony\Component\Yaml\Parser;

$parser = new Parser();
$data = $parser->parse(file_get_contents($path_to_file));

Config is well covered in the docs, e.g. https://www.drupal.org/developing/api/8/configuration/simple