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

100 folders for 100 posts?

Solved by Jared View solution

Started by MD 8 years ago · 7 replies · 1304 views
8 years ago

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?

8 years ago

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

8 years ago

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.

8 years ago

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

8 years ago Solution

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?

👍 2
8 years ago

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

Hahaha. It is almost done now 😃

@doson:
This way.

Blog (Folder)

– 1st Post.md

– 2ndPost.md

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

8 years ago

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

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.

👍 1

Suggested topics

Topic Participants Replies Views Activity
General · by Hanns Mattes, 3 weeks ago
1 266 3 weeks ago
General · by Andy Miller, 3 weeks ago
0 194 3 weeks ago
General · by Jerry Hunt, 3 weeks ago
2 330 3 weeks ago
General · by pamtbaau, 3 weeks ago
1 253 3 weeks ago
General · by Andy Miller, 3 weeks ago
0 220 3 weeks ago