Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slice bounds out of range #2466

Closed
wsokc opened this issue Sep 17, 2016 · 3 comments
Closed

slice bounds out of range #2466

wsokc opened this issue Sep 17, 2016 · 3 comments
Labels

Comments

@wsokc
Copy link

wsokc commented Sep 17, 2016

Hi,

When I try to slice the .Summary I've got the error like this:
y 3 ...>: error calling slicestr: slice bounds out of range in theme/partials/blog.html ERROR: 2016/09/17 22:32:13 template.go:131: template: theme/partials/blog.html:39:34: executing "theme/partials/blog.html" at <slicestr .Summary 3 ...>: error calling slicestr: slice bounds out of range in theme/partials/blog.html ERROR: 2016/09/17 22:32:13 template.go:131: template: theme/partials/blog.html:39:34: executing "theme/partials/blog.html" at <slicestr .Summary 3 ...>: error calling slicestr: slice bounds out of range in theme/partials/blog.html

And my code is:
<div class="content"> <ol class="breadcrumb"> {{ if isset .Params "categories" }} {{ if gt (len .Params.categories) 0 }} in <a href="{{ $.Site.BaseURL }}categories/{{ index .Params.categories 0 | urlize | lower }}">{{ index .Params.categories 0 }}</a></li> {{ end }} {{ end }} </ol> <h6><a href="{{ .Permalink }}">{{ .Title }}</a></h6> <p> {{slicestr .Summary 3 200}} </p> <a href="{{ .Permalink }}">Read More</a> </div>

Is this known error ?

@moorereason
Copy link
Contributor

I'm assuming your summary is less than 200 words. This is a bug in your template, not Hugo. Try slicestr without a limit, check the len of the result, then make the summary the first X where X is len or 200, whichever is smaller. Continue the conversation in the forums.

@wsokc
Copy link
Author

wsokc commented Sep 17, 2016

Thanks,

Yes, now I got someone helped me out from forum.
https://discuss.gohugo.io/t/limit-the-summary/4103/8

Cheers,
Raff

@github-actions
Copy link

github-actions bot commented Apr 3, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants