I’d really benefit from being able to reach any kind of higher-order context from a shortcode. In particular, I have a shortcode that should render nothing if the current output format is RSS/Atom but even if I set such a format on the .Scratch there’s no way to read the scratch from the shortcode.
Will print "html" and not "atom" in my /index.xml file. This doesn’t make sense to me, since the "html" is only set on the scratch in layouts/_default/baseof.html, which isn’t the template being rendered. I ran into this same problem in a totally different context trying to branch templating behavior based on Scratch behaviors and it made me feel like compilation of partial templates is being memoized or something.
What I’m trying to accomplish is if-else branches in templates and shortcodes based on whether an HTML file is being rendered or my RSS feed. Because there’s (AFAICT), no built-in variable or method to report the currently-rendered output format, I’m trying to set it in the scratch.
To try to achieve this, I am setting a .Scratch.Set "output-format" "atom" from the top of my Atom feed list.atom.xml file and setting .Scratch.Set "output-format" "html" from the top of my layouts/_default/baseof.html file. Goal being to be able to branch inside templates/partials/shortcodes based on output format (e.g. {{- if eq (.Page.Scratch.Get "output-format") "html" -}} )
Yes, if I understand you right. It’s why I’m trying to set some kind of higher order variable like a scratch so that the .Content will render differently based on whether the overall file being rendered is an HTML file or my Atom/XML feed
The current main reason why this is is that we reuse, especially, rendered content, across output formats if possible. If you had 2 output formats (HTML + RSS), 10K markdown files and 10 languages that would need to render 200K markdown files if we couldn’t reuse anything.
Thanks, that’ll work! In my case leaving transcript.html as-is and an empty transcript.atom.xml is working as you’d hope and the right layout is calling the right one.