Error with tags and slicestr .summary


#1

Hi, I’m still new to Hugo and I’m having a hard time with tags. I’m using the ([Meghna] theme. I added a single tag to a post in the frontmatter:
tags: [“crypto”]
but I get an error with slicestr for the summary of the posts. See error message below:

Does anyone know what happens?

Also if I remove slicestr, then the error disappears but I don’t see any tags on my posts? Is it not automatic?

Thanks a lot for your help.


#2

I am guessing here, but you could have a .Summary that is less than 150 characters long?

I don’t know what that has to do with tags, it’s difficult without seeing actual code (not just screenshots).


#3

Hi,
Thanks for your message.
Here is the template I’m using:
https://github.com/themefisher/meghna-hugo
with the only change being {{slicestr .Summary 0 150 | markdownify}} on line 20 in list.html in layouts/_default


#4

As I said above, the slicestr error is probably caused by content/summary that is less than 150 characters long. Try doing a test first on the length of the .Summary:

{{ if gt (len .Summary) 150 }}
  {{ slicestr .Summary 0 150 | markdownify }}
{{ else }}
  {{ .Summary | markdownify}}
{{ end }}

As for tags, you need to add template code to render that, as the theme you are using does not seem to do that itself. Have a read here for some ideas: https://gohugo.io/templates/taxonomy-templates/#example-list-tags-in-a-single-page-template


#5

Thank you so much, it’s working perfectly.