[SOLVED] Referencing Children _index.md Content in Parent List Views

Hi There,

I have a nested location-based structure like this:
state -> city -> service

See mockup here: http://regionalinfo.org/

Within each directory I have _index.md that has meta data such as state name OR city wikipedia page, etc.

To get my mockup working I had to implement two markdown files for each directory though, one is the _index.md within each directory and the other is within the parent directory.

For example:

├── california/
│   └── los-angeles/
│       └── _index.md
│       └── police.md
│       └── fire.md
│   └── los-angeles.md <--- DUPLICATE OF /los-angeles/_index.md
│   └── san-francisco/
│   └── san-francisco.md <--- DUPLICATE OF /san-francisco/_index.md

Within my .md files I have a param called ‘level’ which is set to “state”, “city” or “service”

Then within my list.html template I have conditional statements for the types of views:

  • IF home page level THEN print states below
  • IF state level THEN print cities below
  • IF city level THEN print services below.

For Example:

{{if eq .Params.level "state"}}
    {{- range (where .Data.Pages "Params.level" "city")}}
        {{ .Render "li-state" }}
    {{- end }}
{{ end}}

Is there a more efficient way to do this AND eliminate the need for the duplicate markdown file so my range/where statements can reference _index.md files in subdirectories below?

Thanks for your help!
A.J.

I don’t know whether you’ve seen this thread but I asked a similar question and Mikhail has suggested a workable solution. You still need to specify which sections can be listed in the template but that could be put as an option in the site config.

I had not seen that thread. Solution worked perfect! Thanks.

1 Like