Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Forms & Blueprints

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

admin twig

Solved by pamtbaau View solution

Started by Vadim 2 years ago · 4 replies · 312 views
2 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!

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

2 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
2 years ago

Thanks a lot! This works perfectly well.

Suggested topics

Topic Participants Replies Views Activity
Forms & Blueprints · by Ton Haarmans, 5 years ago
13 1138 4 months ago
Forms & Blueprints · by Hugo Oliveira, 5 months ago
0 62 5 months ago
Forms & Blueprints · by Flachy Joe, 6 months ago
9 136 6 months ago
Forms & Blueprints · by Augustus, 7 months ago
7 110 7 months ago
Forms & Blueprints · by Julien, 7 months ago
10 130 7 months ago