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

template function: passing sub result to slicestr #1347

Closed
benzwu opened this issue Aug 10, 2015 · 5 comments
Closed

template function: passing sub result to slicestr #1347

benzwu opened this issue Aug 10, 2015 · 5 comments

Comments

@benzwu
Copy link
Contributor

benzwu commented Aug 10, 2015

{{ substr .Title 0 (sub (len .Title) 1) }}

got this error

executing "theme/_default/list.html" at <1>: wrong type for value; expected int; got int64

from http://discuss.gohugo.io/t/template-list-of-content-adding-s-to-section-name-as-page-title-title/1547

@bep
Copy link
Member

bep commented Aug 10, 2015

What Hugo-version did you test with? I'm pretty sure this was fixed at some point recently.

@bep
Copy link
Member

bep commented Aug 10, 2015

See 51cabe6

@benzwu
Copy link
Contributor Author

benzwu commented Aug 10, 2015

Hugo Static Site Generator v0.15-DEV BuildDate: 2015-08-08T21:02:13+07:00

My bad. I copied the wrong line. It was not substr, It was slicestr.

Checked the source,

the int conversion applied to substr but not slicestr

    var start, length int
    toInt := func(v interface{}, message string) (int, error) {
        switch i := v.(type) {
        case int:
            return i, nil
        case int8:
            return int(i), nil
        case int16:
            return int(i), nil
        case int32:
            return int(i), nil
        case int64:
            return int(i), nil
        default:
            return 0, errors.New(message)
        }
    }

@benzwu benzwu changed the title template function: passing sub result to substr template function: passing sub result to slicestr Aug 10, 2015
@bep
Copy link
Member

bep commented Aug 11, 2015

OK, a pull request is welcomed! (put that toInt-func outside the method for starter).

@bep bep added the Bug label Aug 12, 2015
@bep bep closed this as completed in 5b51b3b Aug 14, 2015
tychoish pushed a commit to tychoish/hugo that referenced this issue Aug 13, 2017
@github-actions
Copy link

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 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants