Template function `jsonify` produces unexpected output

I’ve been trying to use jsonify to troubleshoot and generally just to be able to see all of the available variables. Some of the variables are empty in the result but when the var is referenced directly, it contains a value. For example, when outputting {{ .Permalink }} the value is there but the “Permalink” element of the JSON resulting from jsonify is empty. I have a test repo that illustrates this. Is this a bug?

Also, I noticed that Slug is always empty unless it’s specified in the front matter. Is this expected? My use-case for this is to be able to reference via absolute path some piece of media (like an image) that is in a directory of the same name as the slug for the piece of content. In other words: if I have post/new-post.md, I put images for that in a dir with a naming convention of post/new-post/img/*. I’d like to create a gallery or some such thing by cycling through that dir but I can’t get the dirname from the available variables for a page.


As to jsonify, it just passes the object to json.Marshal (part of Go’s stdlib), so check that doc for limitations. It will not encode funcs and unexported variables.

Thanks @bep. I suspected as much regarding jsonify but what about the missing Slug? My mention of this is unrelated to jsonify. Simply outputting {{ .Slug }} results in emptiness. See here. I’ve discovered this while trying to build a path to an image related to a piece of content. Consider this structure:

└── content
    ├── sponsor
    |   ├── test-sponsor.md
    |   ├── test-sponsor
    |   |   └── logo.jpg

… in a footer partial template, I’d like to display the sponsor information and infer the path to the logo.jpg based on the path/slug of the content. In working through this, I discovered that Slug is empty. So, I’m wondering why that’s empty but also how I can build the path to the logo.jpg.

There is a Slug discussion on GitHub (use the search there). My conclusion there: Slug is a user defined variable; if not provided by the user there is nothing to put there.

Ok, I think you mean https://github.com/spf13/hugo/issues/1815. Per that thread, I’ve used .Source variables to build the path. I was unable to find any documentation on those variables which made that difficult. Any suggestions for finding what’s available in .Source?