Hello.
I moved my old blog posts to Hugo.
Now i want save comments for posts and render it by partial.
I put comments data to separate files <postId>.json
and save it in data/comments
Also I add variable postId
to each post file.
Now i try to get comments for post in partial:
{{- $entryId := .Params.postId }}
{{- $commentsData := $entryId | .Site.Data.newsComments | printf "%s"}}
and it`s not working.
I need help.
Please post a link to the public repository for your site.
regis
3
index
should work, does it not?
{{ $commentsData := index .Site.Data.newsComments $entryId }}
I’d recommend using with
to make sur your index
actually returned something before using it.
Unfortunately, its doesn
t help
{{- with .Params.entryId -}}
{{- $commentsData := index $.Site.Data.newsComments . -}}
{{ println . }}
<ul>
{{- range $commentsData }}
<li>{{ .author }}</li>
{{- end }}
</ul>
{{- end -}}
Also, make sure you are in the feature/comments
branch. The master
branch doesn’t have any data files.
You are welcome. @regis had an excellent suggestion:
I’d recommend using with to make sure your index actually returned something before using it.
system
Closed
9
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.