Data failing to display Please help


#1
data
└── members
    └── list.toml
layouts/
├── index.html
├── listing.html
└── member
    ├── list.html

└── partials
    ├── members-list.html
    ├── navigation
    │   └── navigation.html
    ├── pagination.html
    ├── submenu.html
  
content/
├── member
│   ├── committee-members.md
│   ├── list.html
│   └── membership.md

/layout/member/list.html

{{ range $.Site.Data.members }}
    {{ partial "members-list.html" . }} 
{{ end }}

/data/members/list.toml

listofmembers = [
"user1",
"user2"
]

/layouts/partials/members-list.html

<ul>
	{{ range .listofmembers }}
	  <li> {{ . }}</li>
	{{ end }}
</ul>

Navigating to locahost/members/list gives the following in plaintext:

{{ partial “members-list.html” . }} {{ end }}

What am I doing wrong here?


#3

You can’t use template functions (like range) in content.


#4

I’ve just moved in from jekyll, I’ve spent a long time reading through the documentation but, I still havent got my head around it all evidently.

How should I be arranging this if not via content?


#5

I’ve moved the content into layouts/member

I’ve also removed the header fluff from the file


#6

And it doesn’t work?


#7

after removing the +++ header fluff I’ve got it showing:

{{ partial "members-list.html" . }} {{ end }}

in plaing text, which suggests it is at least… processing something.


#8

Look into your gitter PM


#9

cheers


#10

@Nick_Hoskins I am sure that @bogem already solved this for you in your Gitter PM, but in the event that this thread is found by other users, I wanted to add to the thread here to see if the following solves your use case. I think the problem is that your templating and project structure above confuses range, partial, and also content views, the last of which take advantage of the .Render function. Instead, this can be greatly simplified if the idea is that you want to use that same data file in a partial in multiple locations…

<!--layouts/partials/members-list.html-->
<ul>
{{ range $.Site.Data.members.list.listofmembers }}
	<li>{{.}}</li>
{{ end }}
</ul>

Then in whichever templating file you want to use, just add the following to call the partial…

{{partial "members-list.html" . }}

And your data will write to the page.

That said, you mention your project directory is set up such that you have layouts/member/list.html. This is going to be used as the list page (i.e., the index page) for your member section, which means you will need a corresponding content section for that page (i.e., content/member), so I’m a bit confused.

Note: The dot (.) in Go templates has special meaning when added to that partial. It’s a little more advanced and something you might want to play with, but if you want to make that partial even more usable for multiple types of data files, keep in mind that you can pass other values into the context. Here is a good example from the current Hugo website:

https://github.com/spf13/hugo/blob/master/docs/layouts/index.html#L178

You can also sort, filter, and limit your data. For example, from the Hugo docs concept site:

https://github.com/rdwatters/hugo-docs-concept/blob/master/themes/hugo-docs-concept/layouts/partials/homepage/homepage-tweets.html#L2

HTH.


#11

I still don’t get it. What’s the purpose of a partial if I can’t reuse it?
If i pass the context to a partial, why I can’t access a var in that context?

If I have something like this:

{{ range $service := .Site.Data.services }} {{ partial "_service.html" . }} {{ end }}

how can i access the $service var inside the partial?


#12

Do one of these:

{{ range .Site.Data.services }} {{ partial "_service.html" . }} {{ end }}
{{ range $service := .Site.Data.services }} {{ partial "_service.html" $service }} {{ end }}

#13

The second one worked, thanks.