100 folders for 100 posts?


#1

Just a question.

If i have 100+ blog posts. Will I have to make 100+ folders (i.e 1 folder for every post)? or One single folder (eg. Blog) is enough to put all the blog posts?


#2

Sorry, I don’t have the answer, but I am also interested in the answer to this!


#3

Hi Doson,
You would want 100 folders, one per post. Within each folder would be your md file (blog_item.md or whatever) which has your blog entry text and also any other things for that post (images, videos, etc) so that the folder structure is similar to a database entry for each post. You can put these post folders under a Blog folder if you like.


#4

ty. Is there a way to put all the blog posts, media under one folder (eg. Blog) without any sub-folders.

This way.
Blog (Folder)
– 1st Post.md
– 2ndPost.md

instead of like this
Blog (Folder)
– 1st-post (folder)
– item.md


#5

The way Grav knows what template to use for your text is based on the file name of the markdown folder so basically post1.md, post2.md would need to equate to a template: post1.html.twig, post2.html.twig etc. You really would not want to do that.

You can put all your images, videos, etc in central “images”, “videos”, etc. folders but the md file itself needs to match the twig template that renders it eg blog_post.md

Is it the creation of 100+ folders that sounds like a loooong boring Saturday night?


#6

Hahaha. It is almost done now :smiley:

If you guys can have alternatives. This way would be nice, clean & more simple :smiley:


#7

Template can be specified on a per file basis on the header/frontmatter of the .md file. It then override the default behavior based on the filename .

template: custom

See documentation for more.


#8

Further to this, create a folder with a custom template that has a twig for loop, and have a page collection in the folder’s main md file, eg., {% for pg in page.collection %}. Then put all the blog posts into a sub-folder, each with a similar name so a simple regex will pick them up. Then have the page collection pick up the blog posts. Each blog file should then have template: blog (or other template you want) in the header. Consequently, when your top file template iterates through the blog posts, all you need to do is {{ pg.content }} inside the for loop.