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

SubFolders and Collections

Started by Muut Archive 11 years ago · 12 replies · 1706 views
11 years ago

I am trying to understand how I can setup sub folders and how to control that the parent folder can see items from subfolders. So for example, let's take the Blog Skeleton example. Say I wanted to have:

-blog
subblog 1
item 1
item 2
item 3
subblog 2
item 4
item 5

when I view /blog it should show: item 1 - item 5
when I view /blog/subblog 1 it should show : item1-item3
when I view /blog/tag:birds it should show any item in subblog folder with tag=birds
when I view /blog/subblog 1/tag:birds it should show only subblog1 items with that tag=birds

How do I do this? It almost works with the default skeleton, but on the /blog page I see 'subblog' as an item. So how do I tell the difference from a 'subfolder' and a real 'item'? Is this controlled by the TWIG or how I define the collection?

In the /blog/blog.md file:

TXT

title: Blogs
blog_url: blog
body_classes: header-image fullwidth

sitemap:
changefreq: monthly
priority: 1.03

content:
items: @self.children
order:
by: date
dir: desc
limit: 5
pagination: true

feed:
description: Sample Blog Description
limit: 10

pagination: true

TXT


# My Gravtastic Blog
## A tale of **awesomazing** adventures
---
11 years ago

Also - forgot to mention that when I view:

/blog

it does not show any items that are in the subblog folders

so I do I tell the collection to go to subfolders? Where is this type of stuff documented so I do not have to ask such basic questions.

Thanks

11 years ago

You really need to paste these types of things between triple backticks (click the question mark in the forum text input box for help). I really can't make any sense of your example structure because there are no indents.

11 years ago

Sorry - I hate when that happens and Muut does not let you edit a post

basically trying to figure out how to include items in top level folder that are items from a subfolder:

Folder structure

TXT
blog
  >>subblog 1
    >>>>item 1
    >>>>item 2
    >>>>item 3
  >>subblog 2
    >>>>item 4
    >>>>item 5

when I view /blog it should show: item 1 – item 5 (that are items of a subfolder)
when I view /blog/subblog 1 it should show : item1-item3
when I view /blog/tag:birds it should show any item in subblog folder with tag=birds
when I view /blog/subblog 1/tag:birds it should show only subblog1 items with that

11 years ago

There is a new feature coming in the next release of Grav that will make this easier. https://github.com/getgrav/grav/issues/341

it's possible now, but you would have to ensure that all pages were built with appropriate taxonomy.

For example all your subblog1 item 1-3 pages could have a taxonomy like:

YAML
taxonomy:
  category: [blog, sublog1]

and all your items in subblog2 pages, ie item 4-5 pages would have this:

YAML
taxonomy:
  category: [blog, sublog2]

Then your blog.md page header would setup the collection like this:

YAML
content:
   items:
      @taxonomy.category: blog

And your subblog1.md page would have it's collection setup like this:

YAML
content:
   items:
      @taxonomy.category: sublog1

So from the top level you get every page with category blog and then when your on the subblog1 page you only see pages with the subblog1 category.

Pretty easy!

11 years ago

I almost figured that out myself, but it still does not get the 'child items':

in blog/blog.md

YAML
content:
    items: 
        @taxonomy.category: blog

and in subblog1/blog.md

YAML
content:
    items: @self.children

which works beuatifully on the subblog pages /blog/subblog1,

but does not show item1 from subblog1 - how does

TXT
@taxonomy.category: blog

know to go a few levels deep, it seems to just find items in the current level.

Screen Shot 2015-10-20 at 12

Notice:
http://lp20poc-seatme.rhcloud.com/blog

does not show "SubBlog Item" that exeists in

http://lp20poc-seatme.rhcloud.com/blog/subBlog

11 years ago

When the pages are processed, it creates a taxonomy mapping for every page and their taxonomies. So it will find pages based on taxonomy no matter where they are in your site.

What does the page header of your /blog/subblog1/item1/item.md file contain (or whatever it is called).

11 years ago

BTW you get 3 minutes to make changes with muut forum :)

11 years ago

yeha that would have been helpful:

/blog/subblog1/item1/item.md

YAML

title: SubBlog Item
date: 13:34 06/21/2014 
taxonomy:
    category: blog
    tag: [ocean, birds, photography]
    product: RhoMobile
---
11 years ago

So probably a caching thing - seems to be working now after I changed settings in system.yaml to turn off cache and page expifre to be 60 seconds

Thanks for speedy replies. Awesome

11 years ago

No problem. FWIW I usually run with cache off in development to be safe. it's a bit slower, but better than wasting time on a caching issue.

And slower is relative when Grav is so fast anyway :)

11 years ago

on a somewhat related question - can you have multiple types of collections on a page

like

YAML
content:
    items: 
        @taxonomy.category: blog
    items2:
        @taxonomy.category: subblog

on my main /blog page, I want to:

1) Display blogs in main list area
2) Display list of subblog in sidebar

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1344 9 years ago
Archive · by Muut Archive, 9 years ago
2 930 9 years ago
Archive · by Muut Archive, 9 years ago
2 4058 9 years ago
Archive · by Muut Archive, 9 years ago
1 2943 9 years ago
Archive · by Muut Archive, 9 years ago
3 1116 9 years ago