Skip to content
● Critical PHP security fixes are out: update PHP on your Grav sites. What to do →

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

admin twig

Solved by pamtbaau View solution

Started by Vadim 3 years ago · 4 replies · 1035 views
3 years ago

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!

3 years ago

@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.

last edited 03/20/24 by pamtbaau
3 years ago

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.

3 years ago Solution

@VadiOs, I was hoping my hints would suffice...

Try:

TWIG
{{ (read_file('user-data://my-form/file.yaml')|yaml_decode).value }}
👍 2
3 years ago

Thanks a lot! This works perfectly well.

Suggested topics

Topic Participants Replies Views Activity
Forms & Blueprints · by TomW, 3 days ago
3 76 2 days ago
Forms & Blueprints · by Japhy, 3 weeks ago
2 393 2 weeks ago
Forms & Blueprints · by FrViPofm, 1 month ago
5 395 1 month ago
Forms & Blueprints · by Ton Haarmans, 6 years ago
13 2385 8 months ago
Forms & Blueprints · by Hugo Oliveira, 9 months ago
0 842 9 months ago