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

How to rename a user uploaded file through YAML

admin

Started by Alessandro Ferrari 7 years ago · 2 replies · 1788 views
7 years ago

So basically i added a form in a theme settings page so the user can upload his own logo, however i want the uploaded file to be called as 'logo'.png. Is there an option to rename the file?

7 years ago

@dev_on_a_journey, Would you mind sharing why you would like the uploaded file to have predefined name?

When using the file field in the 'blueprints.yaml' of your theme, it will save the uploaded file into the desired destination folder and write the file's properties into '/user/config/themes/your-theme.yaml'. Then, in Twig, you can retrieve the uploaded file's properties (e.g. name, path) by referencing the theme's config.

See How to: Add a file upload for more explaination and samples.

7 years ago

@pamtbaau Yeah you are right, I'm a beginner I didn't know that. I solved by using a Twig code took from a theme. Later today I'll upload the code! Thank you!

Suggested topics

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