Use .Scratch (or other params) in a shortcode

So I’m trying to get different content in my posts page than in my feed (specifically, it’s rendering a gfycat with their javascript include on the site, which won’t show up in a feed reader.) I’d also like to do things like add a standard email signup in a shortcode. For these things I’d need to use the scratch or the site params, which don’t seem to be available from a shortcode.

So, if there’s a way to do it, could someone tell me? If not, consider it a feature request. :slight_smile:

Bot Scratch (.Scratch) and site params (.Page.Site.Params) are available. I believe this is in the documentation?

The documentation does imply that, yes, but the value of the dot in the
shortcodes is the values passed into the shortcodes. {{.Scratch.Get}} in
that context always returns a zero value for me.

So Scratch returns something, but you get zero value from Get? If so, it may be a timing issue it set outside of the shortcode …?

If not, I may be confused about the Hugo versions (I added this delegate “some time ago”). But in 0.14 this works:

{{$.Page.Scratch.Get}}

I thought that would work, but sadly it doesn’t. If you like, here’s my shortcode and here’s a sample of where it’s being called. None of the stuff we’ve talked about here is working.

  • {{$.Page}}: blank string
  • {{$.Page.Scratch}}: empty map (even when I’m setting and can get the value from scratch in the containing page)
  • {{$.Page.Scratch.Get "value"}}: blank string

The same thing happens with just {{.Scratch}} and friends. This sounds like a regression, would you like me to open an issue?

Oh and yes, I could see it being a timing issue. I’m setting the scratch value in the RSS template, right at the head. Is there a better place for it?

When the RSS template is rendered, the Page content is already rendered – including all the shortcodes. So you can pass values from the shortcodes to the template, but not the other way around.

I see. So how could I change the content for my feed, then?

I guess you currently can not. The content is rendered once .

You would have to put those, say, below the content .