Can't get .GetPage to work consistently in shortcode

I’ve created a shortcode article that accepts a path as an argument.

{{< article >}}

The shortcode itself looks like this:

{{with .Get 0}}
    {{$filename := .}}
    {{with site.GetPage $filename}}
            {{$author := .Param "author"}}
            {{with .Param "image"}}
                <figure class="author">
                    <img src="/assets/img/author/{{.}}" alt="{{$author}}">
            <p class=signature>
                <strong>{{$author}}</strong><br>{{.Param "title"}}

For some reason this code loads some files fine, while it fails the while clause on others and doesn’t get the file. If I include a debug line to show site.GetPage $filename I get the value nopPage returned on the files that don’t show up.

Is this some permissions issue? Anyone have any ideas?

You are more likely to receive a prompt and accurate response if you post a link to the public repository for your project.


Let us see your code

Include a link to the source code repository of your project, because we really need the context of seeing your templates and partials to be able to help you. It is trivial to do a quick git clone on your repo, then run hugo server in your project, to help you out. On the other hand, recreating your code from screenshots, or sort of guessing at it, is not.

If you can’t share your repository for whatever reason, consider creating a dummy repo that you can share, which reproduces the problem you’re experiencing.

Thanks. I’ll do that.

I think I set this up correctly. Please let me know if this helps:

I really appreciate the assistance and advice.


No sooner do I post this…

I think I set up the first issue (/issues/01) as a leaf bundle instead of a branch. Renaming to seems to have resolved the issue.

Derp! Live and learn.

Thanks again for your quick response.


1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.