Data from "user://data" folder in TWIG templates

Hello good people!

I have a form. When the user submits it, the yaml file in the user/data folder is created. Let’s call it “file.yaml”. So the path looks like this: “user/data/my-form/file.yaml”. It has following content:
value: 123

Is there any way how I can display this value in the TWIG template of my theme? I tried something like:
{{ get(‘user://data/my-form/file.yaml’).value }}

But it doesn’t work.

Thanks a lot in advance!

@VadiOs, Have you had a chance to read the docs on Twig Tags, Filter & Functions and the available functions and filters?

Btw. You can also use stream user-data:// to get the data folder.

Hi @pamtbaau! Thanks a lot for your feedback. I checked the documentation but I am still not able to get the data I need. Probably I am doing smth wrong. If I could have a working example of data folder usage in Twig templates that would help a lot.

From what I am reading in documentation you can’t do it without writing a plugin.

@VadiOs, I was hoping my hints would suffice…

Try:

{{ (read_file('user-data://my-form/file.yaml')|yaml_decode).value }}
2 Likes

Thanks a lot! This works perfectly well.