Scratch variable set in Shortcode not available from the template of a Parent Page

I have made a small test repo to keep it simple GitHub - Oliver-Fish/hugo-scratchpad: small test case for issue with hugo scratchpad

Steps to re-produce

Launch Hugo with

hugo server -D

See that the HTML output is

<!DOCTYPE html>
<html lang="en">

<head><script src="/livereload.js?mindelay=10&amp;v=2&amp;port=1313&amp;path=livereload" data-no-instant defer></script>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <h1>some question</h1>
    <h1 id="page-title">Page Title</h1>
<ul>
<li>Some answer here</li>
</ul>

</body>

</html>

Make a change to layouts/test/single.html forcing the live reload to fire, HTML output is


<!DOCTYPE html>
<html lang="en">

<head><script src="/livereload.js?mindelay=10&amp;v=2&amp;port=1313&amp;path=livereload" data-no-instant defer></script>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <h1></h1>
    <h1 id="page-title">Page Title</h1>
<ul>
<li>Some answer here</li>
</ul>

</body>

</html>

alternatively you can re-produce without the live-reload by running with the command

hugo server -D --disableFastRender

With this flag set the scratchpad will always yield an empty output.

@Oliver-Fish

I confirm the issue and as far as I can tell it looks like a bug.

I am tagging @bep because he might want to have look into this.

P.S. I have moved your post to a new topic, because this is a separate issue from the one you originally opened.

2 Likes

Does anyone have some suggestions on what the issue here might be? and ideally, some pointers of files to look at.

I have quite a lot of experience with Go but none with the Hugo codebase so any resources to get familiar with the codebase would be a big help.

I might have some time to look into this next week if no one has by then,

I suggest that you open an issue on GitHub before attempting to work on this.

Also here are the search results for .Sratch in the source code

I have been doing some more checking for this behavior.

The very interesting thing is that the Shortcode Scratch is rendered on the local server only in Fast Render mode.

If --disableFastRenderMode is used then the Scratch is missing even on the first build.

Also the Scratch is not outputted when the project is published with the command hugo.

P.S. I deleted my previous answer as my assumption was incorrect. The rendering order does not seem to have to do much with it. Since Shortcodes are rendered first I would expect that a Scratch variable set in a Shortcode would be available in the Parent Page.

I have opened:

So I am closing this topic in favor of the GitHub issue.