Shortcodes not working

Hi,

I have a need in my site to be able to create columns of text (I’m using Foundation 5). I intend to create a row div, then have some text which needs to be in a columns div and then something else which will be in a columns aside, like this:

<div class="row">
<div class="large-8 columns">
Some text in here.
</div>
<aside class="large-4 columns">
My aside text here.
</aside>
</div>

So, I created 3 shortcodes in /layouts/shortcodes:

<!-- aside -->
<aside class="large-4 columns">
{{ .Inner }}
</aside>
<!-- aside -->

<!-- column -->
<div class="large-8 columns">
{{ .Inner }}
</div>
<!-- column -->

<!-- row -->
<div class="row">
{{ .Inner }}
</div>
<!-- row -->

These are to be used inside my mardown as:

{{% row %}}
{{% column %}}
This goes into a column.
{{% /column %}}

{{% aside %}}
This goes into an aside.
{{% /aside %}}
{{% /row %}}

but hugo complains:

INFO: 2014/11/10 Using config file: /home/laguest/src/mine/archeia-website/website/config.toml
INFO: 2014/11/10 syncing from /home/laguest/src/mine/archeia-website/website/themes/archeia/static/ to /home/laguest/src/mine/archeia-website/website/public/
INFO: 2014/11/10 syncing from /home/laguest/src/mine/archeia-website/website/static/ to /home/laguest/src/mine/archeia-website/website/public/
ERROR: 2014/11/10 error processing shortcode shortcodes/column.html 
 ERR: html/template:shortcodes/column.html: "shortcodes/column.html" is an incomplete or empty template
WARN: 2014/11/10 &{[] <p>This shit goes into a column.</p>
 0xc20808a840}
ERROR: 2014/11/10 error processing shortcode shortcodes/column.html 
 ERR: html/template:shortcodes/column.html: "shortcodes/column.html" is an incomplete or empty template
WARN: 2014/11/10 &{[] <p>This goes into a column.</p>
 0xc20808a840}
ERROR: 2014/11/10 error processing shortcode shortcodes/aside.html 
 ERR: html/template:shortcodes/aside.html: "shortcodes/aside.html" is an incomplete or empty template
WARN: 2014/11/10 &{[] <p>This goes into an aside.</p>
 0xc20808a840}
ERROR: 2014/11/10 error processing shortcode shortcodes/row.html 
 ERR: html/template:shortcodes/row.html: "shortcodes/row.html" is an incomplete or empty template
WARN: 2014/11/10 &{[]  0xc20808a840}
INFO: 2014/11/10 found taxonomies: map[string]string{"tag":"tags", "series":"series", "project":"projects", "category":"categories"}
WARN: 2014/11/10 Unable to locate layout for 404 page: [404.html theme/404.html]
0 draft content 
0 future content 
3 pages created 
1 categories created
1 tags created
0 series created
0 projects created
in 9 ms

My versions:

$ hugo version
Hugo Static Site Generator v0.13-DEV
$ go version
go version go1.3.3 linux/amd64

So, I’ve no idea what is going on, it’s just removing the code completely. I’ve also tried adding {{printf "%#v" .}} but doesn’t do anything either.

I’ve tried updating hugo with go get -u github.com/spf13/hugo but that fails with:

# code.google.com/p/go-html-transform/h5
src/code.google.com/p/go-html-transform/h5/h5.go:30: cannot use "code.google.com/p/go.net/html/atom".Body (type "code.google.com/p/go.net/html/atom".Atom) as type "golang.org/x/net/html/atom".Atom in assignment
src/code.google.com/p/go-html-transform/h5/node.go:92: cannot use "code.google.com/p/go.net/html/atom".A (type "code.google.com/p/go.net/html/atom".Atom) as type "golang.org/x/net/html/atom".Atom in field value

Thanks,
Luke.

1 Like

Shortcodes cannot be nested, and I believe wasn’t added to solve THIS problem.

But I feel your pain, but this illustrates some current shortcomings of Go templates.

@tatsushid may chip in here - to say something about Ace and his Pull request, if that would solve your use case:

Actually the shortcode parser in v0.12 was nestable. I believe it’s still the case for v0.13 though it is a new parser. They are nestable within a content file. You can’t use shortcodes inside the templates, but it doesn’t look like you are doing that.

If Hugo is warning that the templates are in complete than that’s where I would start to look.

What errors do you get with hugo v0.12?

Downloaded it and installed it to the same place as my github built one:

$ hugo_0.12 -v
INFO: 2014/11/10 Using config file: /home/laguest/src/mine/archeia-website/website/config.toml
INFO: 2014/11/10 syncing from /home/laguest/src/mine/archeia-website/website/themes/archeia/static/ to /home/laguest/src/mine/archeia-website/website/public/
INFO: 2014/11/10 syncing from /home/laguest/src/mine/archeia-website/website/static/ to /home/laguest/src/mine/archeia-website/website/public/
ERROR: 2014/11/10 error processing shortcode shortcodes/column.html 
 ERR: html/template:shortcodes/column.html: "shortcodes/column.html" is an incomplete or empty template
WARN: 2014/11/10 &{[] <p>This goes into a column.</p>
 0xc208180b00}
ERROR: 2014/11/10 error processing shortcode shortcodes/aside.html 
 ERR: html/template:shortcodes/aside.html: "shortcodes/aside.html" is an incomplete or empty template
WARN: 2014/11/10 &{[] <p>This goes into an aside.</p>
 0xc208180b00}
ERROR: 2014/11/10 error processing shortcode shortcodes/row.html 
 ERR: html/template:shortcodes/row.html: "shortcodes/row.html" is an incomplete or empty template
WARN: 2014/11/10 &{[]  0xc208180b00}
INFO: 2014/11/10 found taxonomies: map[string]string{"project":"projects", "category":"categories", "tag":"tags", "series":"series"}
WARN: 2014/11/10 Unable to locate layout: [404.html theme/404.html]
0 draft content 
0 future content 
3 pages created 
1 categories created
1 tags created
0 series created
0 projects created
in 9 ms

Can you try the latest from HEAD. I think it resolved this.

did and update, rang hugo, got:

$ hugo
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x20 pc=0x464566]

goroutine 75 [running]:
runtime.panic(0x8f38c0, 0xc3eb93)
/usr/lib/go/src/pkg/runtime/panic.c:279 +0xf5
github.com/spf13/hugo/hugolib.isInnerShortcode(0xc208132880, 0x3)
/home/laguest/opt/go/src/github.com/spf13/hugo/hugolib/shortcode.go:149 +0x86
github.com/spf13/hugo/hugolib.extractShortcode(0x7fb455239938, 0xc208162000, 0x7fb458b35560, 0xc20810c500, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, …)
/home/laguest/opt/go/src/github.com/spf13/hugo/hugolib/shortcode.go:301 +0x884
github.com/spf13/hugo/hugolib.extractShortcodes(0xc20817a000, 0xb68, 0xc208162000, 0x7fb458b35560, 0xc20810c500, 0x0, 0x0, 0x404158, 0x0, 0x0)
/home/laguest/opt/go/src/github.com/spf13/hugo/hugolib/shortcode.go:374 +0x62d
github.com/spf13/hugo/hugolib.extractAndRenderShortcodes(0xc20817a000, 0xb68, 0xc208162000, 0x7fb458b35560, 0xc20810c500, 0x0, 0x0, 0x0)
/home/laguest/opt/go/src/github.com/spf13/hugo/hugolib/shortcode.go:216 +0x86
github.com/spf13/hugo/hugolib.(*Page).ProcessShortcodes(0xc208162000, 0x7fb458b35560, 0xc20810c500)
/home/laguest/opt/go/src/github.com/spf13/hugo/hugolib/page.go:637 +0x77
github.com/spf13/hugo/hugolib.markdownHandler.PageConvert(0x0, 0x0, 0x0, 0xc208162000, 0x7fb458b35560, 0xc20810c500, 0x0, 0x0, 0x0, 0x0)
/home/laguest/opt/go/src/github.com/spf13/hugo/hugolib/handler_page.go:57 +0x63
github.com/spf13/hugo/hugolib.(*markdownHandler).PageConvert(0xc208096560, 0xc208162000, 0x7fb458b35560, 0xc20810c500, 0x0, 0x0, 0x0, 0x0)
:83 +0xcd
github.com/spf13/hugo/hugolib.(*MetaHandle).Convert(0xc208096c80, 0x94a6e0, 0xc208162000, 0xc20802cea0, 0xc20812a900)
/home/laguest/opt/go/src/github.com/spf13/hugo/hugolib/handler_meta.go:69 +0x27f
github.com/spf13/hugo/hugolib.pageConverter(0xc20802cea0, 0xc20812a960, 0xc20812a900, 0xc208116d80)
/home/laguest/opt/go/src/github.com/spf13/hugo/hugolib/site.go:439 +0xfc
created by github.com/spf13/hugo/hugolib.(*Site).CreatePages
/home/laguest/opt/go/src/github.com/spf13/hugo/hugolib/site.go:383 +0x627

goroutine 16 [semacquire]:
sync.runtime_Semacquire(0xc20813c59c)
/usr/lib/go/src/pkg/runtime/sema.goc:199 +0x30
sync.(*WaitGroup).Wait(0xc208116d80)
/usr/lib/go/src/pkg/sync/waitgroup.go:129 +0x14b
github.com/spf13/hugo/hugolib.(*Site).CreatePages(0xc20802cea0, 0x0, 0x0)
/home/laguest/opt/go/src/github.com/spf13/hugo/hugolib/site.go:399 +0x7e4
github.com/spf13/hugo/hugolib.(*Site).Process(0xc20802cea0, 0x0, 0x0)
/home/laguest/opt/go/src/github.com/spf13/hugo/hugolib/site.go:187 +0x96
github.com/spf13/hugo/hugolib.(*Site).Build(0xc20802cea0, 0x0, 0x0)
/home/laguest/opt/go/src/github.com/spf13/hugo/hugolib/site.go:151 +0x4a
github.com/spf13/hugo/commands.buildSite(0xc208113c4f, 0x1, 0x1, 0x0, 0x0)
/home/laguest/opt/go/src/github.com/spf13/hugo/commands/hugo.go:285 +0xcc
github.com/spf13/hugo/commands.build(0x0, 0x0, 0x0)
/home/laguest/opt/go/src/github.com/spf13/hugo/commands/hugo.go:211 +0x268
github.com/spf13/hugo/commands.func·006(0xc3d0e0, 0xc4bdb0, 0x0, 0x0)
/home/laguest/opt/go/src/github.com/spf13/hugo/commands/hugo.go:49 +0x2f
github.com/spf13/cobra.(*Command).execute(0xc3d0e0, 0x0, 0x0, 0x0, 0x0, 0x0)
/home/laguest/opt/go/src/github.com/spf13/cobra/command.go:368 +0x17c
github.com/spf13/cobra.(*Command).Execute(0xc3d0e0, 0x0, 0x0)
/home/laguest/opt/go/src/github.com/spf13/cobra/command.go:416 +0x13c
github.com/spf13/hugo/commands.Execute()
/home/laguest/opt/go/src/github.com/spf13/hugo/commands/hugo.go:60 +0x2f
main.main()
/home/laguest/opt/go/src/github.com/spf13/hugo/main.go:24 +0x30

goroutine 19 [finalizer wait]:
runtime.park(0x4131c0, 0xc4ac30, 0xc43c89)
/usr/lib/go/src/pkg/runtime/proc.c:1369 +0x89
runtime.parkunlock(0xc4ac30, 0xc43c89)
/usr/lib/go/src/pkg/runtime/proc.c:1385 +0x3b
runfinq()
/usr/lib/go/src/pkg/runtime/mgc0.c:2644 +0xcf
runtime.goexit()
/usr/lib/go/src/pkg/runtime/proc.c:1445

goroutine 50 [chan send]:
text/template/parse.lexSpace(0xc20814c200, 0xa72a68)
/usr/lib/go/src/pkg/text/template/parse/lex.go:339 +0xe0
text/template/parse.(*lexer).run(0xc20814c200)
/usr/lib/go/src/pkg/text/template/parse/lex.go:198 +0x40
created by text/template/parse.lex
/usr/lib/go/src/pkg/text/template/parse/lex.go:191 +0x112

goroutine 51 [chan send]:
text/template/parse.lexSpace(0xc20814c280, 0xa72a68)
/usr/lib/go/src/pkg/text/template/parse/lex.go:339 +0xe0
text/template/parse.(*lexer).run(0xc20814c280)
/usr/lib/go/src/pkg/text/template/parse/lex.go:198 +0x40
created by text/template/parse.lex
/usr/lib/go/src/pkg/text/template/parse/lex.go:191 +0x112

goroutine 52 [chan send]:
text/template/parse.lexSpace(0xc20814c300, 0xa72a68)
/usr/lib/go/src/pkg/text/template/parse/lex.go:339 +0xe0
text/template/parse.(*lexer).run(0xc20814c300)
/usr/lib/go/src/pkg/text/template/parse/lex.go:198 +0x40
created by text/template/parse.lex
/usr/lib/go/src/pkg/text/template/parse/lex.go:191 +0x112

goroutine 53 [chan send]:
text/template/parse.lexSpace(0xc20814c400, 0xa72a68)
	/usr/lib/go/src/pkg/text/template/parse/lex.go:339 +0xe0
text/template/parse.(*lexer).run(0xc20814c400)
	/usr/lib/go/src/pkg/text/template/parse/lex.go:198 +0x40
created by text/template/parse.lex
	/usr/lib/go/src/pkg/text/template/parse/lex.go:191 +0x112

goroutine 54 [chan send]:
text/template/parse.lexSpace(0xc20814c480, 0xa72a68)
	/usr/lib/go/src/pkg/text/template/parse/lex.go:339 +0xe0
text/template/parse.(*lexer).run(0xc20814c480)
	/usr/lib/go/src/pkg/text/template/parse/lex.go:198 +0x40
created by text/template/parse.lex
	/usr/lib/go/src/pkg/text/template/parse/lex.go:191 +0x112

goroutine 55 [chan send]:
text/template/parse.lexSpace(0xc20814c500, 0xa72a68)
	/usr/lib/go/src/pkg/text/template/parse/lex.go:339 +0xe0
text/template/parse.(*lexer).run(0xc20814c500)
	/usr/lib/go/src/pkg/text/template/parse/lex.go:198 +0x40
created by text/template/parse.lex
	/usr/lib/go/src/pkg/text/template/parse/lex.go:191 +0x112

goroutine 63 [chan send]:
github.com/spf13/hugo/hugolib.lexShortcodeRightDelim(0xc2080e4240, 0xa71f58)
	/home/laguest/opt/go/src/github.com/spf13/hugo/hugolib/shortcodeparser.go:349 +0xf4
github.com/spf13/hugo/hugolib.(*pagelexer).runShortcodeLexer(0xc2080e4240)
	/home/laguest/opt/go/src/github.com/spf13/hugo/hugolib/shortcodeparser.go:196 +0x40
created by github.com/spf13/hugo/hugolib.newShortcodeLexer
	/home/laguest/opt/go/src/github.com/spf13/hugo/hugolib/shortcodeparser.go:188 +0xe4

goroutine 76 [runnable]:
github.com/spf13/hugo/helpers.ExtractTOC(0xc2080ea000, 0xd9, 0x1ac, 0xd0, 0xc2080ea000, 0xd9, 0x1ac, 0x0, 0x0)
	/home/laguest/opt/go/src/github.com/spf13/hugo/helpers/content.go:112
github.com/spf13/hugo/hugolib.markdownHandler.PageConvert(0x0, 0x0, 0x0, 0xc2080d8000, 0x7fb458b35560, 0xc20810c500, 0x0, 0x0, 0x0, 0x0)
	/home/laguest/opt/go/src/github.com/spf13/hugo/hugolib/handler_page.go:59 +0x10f
github.com/spf13/hugo/hugolib.(*markdownHandler).PageConvert(0xc208096560, 0xc2080d8000, 0x7fb458b35560, 0xc20810c500, 0x0, 0x0, 0x0, 0x0)
	<autogenerated>:83 +0xcd
github.com/spf13/hugo/hugolib.(*MetaHandle).Convert(0xc208116da0, 0x94a6e0, 0xc2080d8000, 0xc20802cea0, 0xc20812a900)
	/home/laguest/opt/go/src/github.com/spf13/hugo/hugolib/handler_meta.go:69 +0x27f
github.com/spf13/hugo/hugolib.pageConverter(0xc20802cea0, 0xc20812a960, 0xc20812a900, 0xc208116d80)
	/home/laguest/opt/go/src/github.com/spf13/hugo/hugolib/site.go:439 +0xfc
created by github.com/spf13/hugo/hugolib.(*Site).CreatePages
	/home/laguest/opt/go/src/github.com/spf13/hugo/hugolib/site.go:383 +0x627

goroutine 78 [chan receive]:
github.com/spf13/hugo/hugolib.converterCollator(0xc20802cea0, 0xc20812a900, 0xc20812a720)
	/home/laguest/opt/go/src/github.com/spf13/hugo/hugolib/site.go:456 +0x9a
created by github.com/spf13/hugo/hugolib.(*Site).CreatePages
	/home/laguest/opt/go/src/github.com/spf13/hugo/hugolib/site.go:386 +0x663

Do you have a public repo that reproduces this?