template function: passing sub result to slicestr #1347

Closed
benzwu opened this Issue Aug 10, 2015 · 4 comments

Comments

Projects
None yet
2 participants
@benzwu
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

This comment has been minimized.

Show comment
Hide comment
@bep

bep Aug 10, 2015

Member

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

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

This comment has been minimized.

Show comment
Hide comment
@bep

bep Aug 10, 2015

Member

See 51cabe6

Member

bep commented Aug 10, 2015

See 51cabe6

@benzwu

This comment has been minimized.

Show comment
Hide comment
@benzwu

benzwu Aug 10, 2015

Contributor

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)
        }
    }
Contributor

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 from template function: passing sub result to substr to template function: passing sub result to slicestr Aug 10, 2015

@bep

This comment has been minimized.

Show comment
Hide comment
@bep

bep Aug 11, 2015

Member

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

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 in 5b51b3b Aug 14, 2015

tychoish added a commit to tychoish/hugo that referenced this issue Aug 13, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment