Hello,
I am currently trying to add a function to the templating system. This one is called widgets. I have added it to tpl/template_funcs.go, and created a test site inside examples/widgets. But when I want to generate the test website, Hugo doesn’t recognize the widgets templating function:
~/dev/go/hugo$ go build
~/dev/go/hugo$ cd examples/widgets
~/dev/go/hugo/examples/widgets$ ../../hugo
Started building sites ...
ERROR: 2016/10/28 00:37:20 template.go:477: template: index.html:4: function "widgets" not defined
ERROR: 2016/10/28 00:37:20 general.go:212: Error while rendering homepage: template: "index.html" is an incomplete or empty template; defined templates are: "_internal/twitter_cards.html", "_internal/google_news.html", "_internal/shortcodes/relref.html", "_internal/shortcodes/speakerdeck.html", "_internal/_default/rss.xml", "_internal/pagination.html", "_internal/disqus.html", "_internal/google_analytics.html", "_internal/_default/robots.txt", "_internal/shortcodes/ref.html", "_internal/shortcodes/highlight.html", "_internal/shortcodes/youtube.html", "_internal/_default/sitemapindex.xml", "_internal/opengraph.html", "_internal/schema.html", "_internal/shortcodes/figure.html", "_internal/shortcodes/vimeo.html", "_internal/shortcodes/tweet.html", "_internal/_default/sitemap.xml", "_internal/shortcodes/test.html", "_internal/shortcodes/gist.html", "_internal/google_analytics_async.html"
~/dev/go/hugo/examples/widgets$
First, thanks for jumping in to try to solve an issue.
Quick thoughts:
No hugo maintainer has signed off on your proposal in #2535. I’m all for people learning Go (yea!), but be prepared to have to redo some/all of this proposal.
You have syntax errors in hugolib/widget.go.
Add gofmt/goimports to your editor/IDE environment.
I would recommend naming the function widget without the trailing “s”. The “s” provides no value.
Much of this feature should mimic how the partial templates work.
Write tests instead of hacking in an examples folder. Simple example that works with what you have:
clone or go get your fork and rename folder to spf13 to match the package imports
clone the original and add your fork as a remote
I use GitHub’s hub tool to do forking, and I just clone or get the original and then do a hub fork when I want to do some changes in a new repo – then I don’t have to think about paths. Then branching and coding … and then hub pull-request when I’m done. Quick as it gets.
I will read again the contributing guide. All to say that I agree completely about a possible rearrange/move to thrash bin (I won’t be offended at all if a pull request does not succeed, if ever I can develop something).
As I do not know about the reviewing/proposal process, I wanted to dive into the widget problem to let the discussion go on (I hadn’t much answers about my proposal so let’s see what it could become !). I still won’t be offended if somebody implemented the whole thing before me, as I would only like a widget system to appear
Actually widgets.go was included in the commit but I did nothing on it. The whole commit was made fastly to begin diving into.
Totally agreeing with you. IMO a widget mechanism is narrower than partials in terms of possibilities (widgets are intended for HTML, which whereas partials are agnostic). See the Widget mechanism thread.
This was my very first draft to explore. Thanks for the test.
Okay thanks @bep for your $GOPATH remark. This is it. Actually I had my forked repository somewhere else, but $GOPATH/src/github.com/spf13/hugo was well cloned from the main source. I made it with symlinks:
~/dev/go/hugo$ go build
# github.com/spf13/hugo/hugolib
../src/github.com/spf13/hugo/hugolib/widget.go:25: syntax error: non-declaration statement outside function body