HUGO

Partial pulling in content sub folder

Hi All, Sorry another question!

The website I’m building will have a reviews section, an image and MD file will provide each review, I’m planning 2-3 per page but they will change between each page.

In my head I want the structure to be like this:

/content/

  • /page/
    –/reviews/
    —/review1.md
    —/review1.jpg
    —/review2.md
    —/review2.img
  • /page2/
    –/reviews/
    —/review1.md
    —/review1.jpg
    —/review2.md
    —/review2.img
  • /page/
    –/reviews/
    —/review1.md
    —/review1.jpg
    —/review2.md
    —/review2.img

I have looked into date but as I want these to be unique to the content folder I think this is the correct way to go.

I’m aware I can use the below code to do this but I already use it for another purpose
{{ with .Resources.ByType “page” }}
{{ range . }}


{{.Content}}

{{ end }}
{{ end }}

Is there a way for me to modify this code to only pull files from a specific folder (/reviews) or do I need to change how I am doing this? Currently with my layout the review I have set up gets pulled into a different content block where I am using the code above.

Thanks for any help - hope it makes sense :slight_smile:

I am afraid I either misunderstand you completely or you are completely wrong. page and page2 are not resources. They are sections. The second page wont work, but I assume for now, that it was supposed to be page3.

There are multiple things that you need to look into:

  1. Sections. Folders inside of the content folder (first level) are called sections and can be queried by Kind which resolves to the foldername or it’s plural.
  2. Page Bundles. Put an index.md inside of page and it becomes a bundle. That will break then the reviewX.md files I think.

You wish to add reviews per page. I would approach that in two ways (depending on the amount of reviews and specificity of reviews):

Method 1: FRONTMATTER

add something like the following structure to your frontmatter (per page):

reviews:
  - title: review 1
    image: src.jpg
  - title: review 2
    image: src.jpg

This should be available via .Params.reviews and can be range-ed. Add whatever info you need like images, description, links.

Method 2: DATA FILES

add a data/reviews.toml to your system where you add reviews. Give those reviews a parameter like tag or category and select from these by frontmatter from a page. That makes sense if you have repeating reviews for several pages.

Thanks, A bit of content

Im creating service area landing pages…

/content/service-area/

This works fine

Essentially I was hoping to organise content in folder rather than front matter, as below

/content/service-area/
/content/service-area/reviews/
/content/service-area/listareas/

I have managed to get it working through front matter which I suppose is just as good, I’ve been able to use your example then range it with the below:

{{ range .Params.review }}
          {{ .image }}
          {{ .title }}
        {{ end }}

Thanks for your help :slight_smile: