Problems with using dynamic media_folder name
- Dominant language
- JavaScript
- Stars
- 19.4k
- Forks
- 3.1k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 9
Description
**Describe the bug**
This is how I define my posts collection
```yml
collections:
- label: Posts
label_singular: post
name: posts
folder: content/posts
media_folder: '/{{media_folder}}/posts/{{filename}}'
public_folder: '{{public_folder}}/posts/{{filename}}'
format: frontmatter
create: true
identifier_field: title
fields:
- {label: Title, name: title, widget: string}
- {label: Cover image, name: cover, widget: image, required: false}
- {label: Body, name: body, widget: markdown}
```
as you can see media_folder name is based on the filename. But the problem is that when you create post file doesn't exist, so images in markdown is written with wrong path.
**How to reproduce**
Here is reproduction repository
https://github.com/smashercosmo/folder-collections-media-and-public-folder-issue
1. run ```npm run develop```
2. open ```http://localhost:8000/admin/```
3. press ```new post```
4. fill the form and upload an image
5. press ```publish```
**Expected behavior**
you should see correct image path in frontmatter
```
---
cover: /img/posts/new-post-name/image.jpg
---
```
**Actual behavior**
you will see this instead
```
---
cover: /img/posts/image.jpg
---
```
**Applicable Versions:**
- Netlify CMS version: 2.12.12
Contributor guide
Assessment
This issue has not been assessed yet.