Error when using GetPage

Before Hugo 0.45.1 I was using this bit to get the params of a taxonomy term.

 {{ $name_url := index .Params.stories 0 | urlize }}
 {{ $this := $.Site.GetPage "taxonomy" "stories" $name_url }}

To upgrade with the new version, I tried the following:

 {{ $name_url := index .Params.stories 0 | urlize }}
 {{ $this := $.Site.GetPage ( printf "stories/" $name_url) }}

I must have done something terribly wrong, because I get the following error:

[?25lBuilding sites … ERROR 2018/07/30 23:59:48 Failed to render "_default/single.html": runtime error: invalid memory address or nil pointer dereference
ERROR 2018/07/30 23:59:48 Stack Trace:
goroutine 2119 [running]:, 0x4c87304, 0x17)
	/private/tmp/hugo-20180725-73794-1meehvy/hugo-0.45.1/src/ +0x76

Can someone please point out where the problem might be?

To be entirely correct you should start with a leading slash, BUT … I think this is a case where looking at your code snippets isn’t enough. It looks like it should be working, so there is something I don’t see.

Ok I have added the / anyway and updated the code on github:

The point of this is to get params of the current story, so if there’s another way to do it, I don’t mind using the alternative.

I figured this out. That form of the printf command was returning a weird string. For example, it returned this: /stories%!(EXTRA string=coffee-table)

The correct form is this: {{ $current_story := printf "%s/%s" "/stories" $name_url }} which will return /stories/coffee-table.

The weird error was because the result was nil and I was trying to output specific params.