New added template function doesn't work

Hi, I wonder how template functions are called in Hugo. I’ve added a new function in ‘template.go’ called Substr and created an alias inside init() function at the bottom like “substr”: Substr, just like the other functions. I’ve also written a test for it in ‘template_test.go’ and it passed fine. Then I rebuilt hugo as the following:

go build -o hugo main.go
mv hugo /usr/local/bin/

But when I tried to re-launch the server again in one of my existing Hugo project like this:

hugo server -w -v

I’ve got an error saying ‘function “substr” not defined’. Not sure what have I done wrong. I’m pretty new to Golang.

Thanks in advance for any help.

As I see it you did everything correct.

This suggests that the Hugo you build with isn’t the Hugo you modified.

I suggest making a cosmetic and visible change to some existing Hugo functionality and verify that your change gets applied.

Then I would look at the Go build setup. Most likely a GOPATH issue (I’m still a little bit confused by this myself, but I suspect what you see is the Hugo source fetched via “go get”)).

Hey guys, thanks for your reply.
It wasn’t the GOPATH issue as I’ve already done the following as suggested in the tutorial:

rm -rf "$GOPATH/src/github.com/spf13/hugo"
ln -s `pwd` "$GOPATH/src/github.com/spf13/hugo"

so the GOPATH src file is just a symbolink to my local repo. However I managed to solve the problem by running the following before I re-build Hugo.

go install github.com/spf13/hugo/hugolib

I didn’t do this before coz I wasn’t sure what is this doing. I think it probably re-install the entire Hugo library on my system somewhere.