[FIXED] Blocks stopped working for section layout?

Hugo version:

Hugo Static Site Generator v0.21-DEV-9EC00725 linux/amd64 BuildDate: 2017-04-10T15:58:13-04:00

I have a baseof.html that looks like this:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en-us">

    {{ partial "head.html" . }}

    <body onload="prettyPrint()" class={{ (print "theme-base-0" .Site.Params.themecolorbase) }} lang="en">

        <!-- Top color border of the page -->
        <div class="border" id="home"></div>

        <div class="wrapper">

            {{ partial "navbar.html" . }}

            <div class="masthead">
                <div class="container">
                    <h1 class="masthead-title">
                        <p class="masthead-title-only">
                            <a href="/">{{ .Site.Title }}</a> <span class="blinking-cursor">❚</span>
                        </p>
                    </h1>
                    <h2 class="masthead-title">
                        <small>
                            {{ .Site.Params.tagline }}
                        </small>
                    </h2>
                </div>
            </div>

            <div class="container">

                {{ block "main" . }}{{ end }}

            </div> <!-- - Closing <div class="wrap"> in default_head.html -->
        </div> <!-- - Closing <div class="container"> in default_head.html -->

        {{ "<!-- Google Analytics -->" | safeHTML }}
        <!-- {{ template "_internal/google_analytics_async.html" . }} -->
        {{ partial "googleanalytics.html" . }}

        <script>
         // Init responsive-nav.js
         var nav = responsiveNav("#nav");
        </script>
    </body>
</html>

I’d like to use the main block definition feature to avoid copy/pasting the default code. So a section layout page: layouts/section/bookmarks.html looks like this:

{{ define "main" }}

Hi

{{ end }}

But that does not work! This worked at the time of 0.19 release, but broke at some point after that…

I do not also get any error when running hugo… just that I see a completely blank page on visiting the generated bookmarks.html.

But if I do not make use of the block feature, and copy paste everything from the baseof.html, it works …

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en-us">

    {{ partial "head.html" . }}

    <body onload="prettyPrint()" class={{ (print "theme-base-0" .Site.Params.themecolorbase) }} lang="en">

        <!-- Top color border of the page -->
        <div class="border" id="home"></div>

        <div class="wrapper">

            {{ partial "navbar.html" . }}

            <div class="masthead">
                <div class="container">
                    <h1 class="masthead-title">
                        <p class="masthead-title-only">
                            <a href="/">{{ .Site.Title }}</a> <span class="blinking-cursor">❚</span>
                        </p>
                    </h1>
                    <h2 class="masthead-title">
                        <small>
                            {{ .Site.Params.tagline }}
                        </small>
                    </h2>
                </div>
            </div>

            <div class="container">

                Hi

            </div> <!-- - Closing <div class="wrap"> in default_head.html -->
        </div> <!-- - Closing <div class="container"> in default_head.html -->

        {{ "<!-- Google Analytics -->" | safeHTML }}
        <!-- {{ template "_internal/google_analytics_async.html" . }} -->
        {{ partial "googleanalytics.html" . }}

        <script>
         // Init responsive-nav.js
         var nav = responsiveNav("#nav");
        </script>
    </body>
</html>

  • Is the method of using block in section layout changed?
  • Is this a bug?

Do you have a repository to link to which shows this issue?

I just pushed a bare min example of this to my test repo: https://gitlab.com/kaushalmodi/hugo_config_idiosyncrasies

This commit probably explains the crux of the setup: https://gitlab.com/kaushalmodi/hugo_config_idiosyncrasies/commit/14b7f64088db75460d2ec51048434096445bea68

After building, the test_section_block.html page will be blank, while the test_section_noblock.html page (built using the version of the section template without the use of block) will show “Hi”.


In the real use case too, I plan to keep content/SECTIONNAME/_index.md as an empty file as that ‘section’ is auto-generated using Data. The layouts/section/SECTIONNAME.html template uses the data toml file in data/foo/bar.toml to construct the contents in the "main" block.

But in the above example, I am able to recreate the blank-page issue without bringing Data into the equation.

It works if you put the base template in the project, or the section template in the theme, which I guess is a change since 0.19, and an issue I could have fixed for 0.20 If reported earlier …

It works if you put the base template in the project

Sorry, which directory would be the ‘project’ here? I put it in _default.

Update: Actually I understood… So I would need to copy the themes/THEME/_default/baseof.html to layouts/_default/baseof.html. But that would be very inelegant… I would like to have only one copy of the master baseof.html in the theme and not have to copy that to each site’s layout/ each time the theme version changes.

, or the section template in the theme

I cannot put the section template in the theme as it is very Data (and site) specific. I plan to use the theme for multiple sites.

which I guess is a change since 0.19

Thanks for confirming. So will this be fixed?

It was also surprising that errors were not thrown during the building. So I did not notice this earlier. Shouldn’t some error be output instead of outputting an empty HTML page?

I am learning to use Data on the side and am using this section template only for that. As I am not publishing this on my blog yet, this didn’t come to my attention until today.

Well, in this case the template (wrongly) evaluated to a empty HTML page, so it is hard to give an error. I don’t think we can error just because the page is blank. That would create many false errors.

Makes sense. Thanks for the explanation.

I have confirmed this bug fix. Thanks!

BLOCK now works with sections but not with taxonomies!

layout/taxonomy/tag.terms.html does not work with BLOCK !
please check this.

Taxonomy and taxonomy terms work fine for me with blocks and, to be a little selfish, that is kind of the most important thing for me. If you have issues with it and want me to look at it, you should open an issue on GitHub where you are as concrete as possible; e.g. with a runnable failing example.

uploaded, hope nothing is missed

gmtju52/spielwiese

Hi,

Mostly fixed in 0.21, but fails where both baseof.html templates exist. The behaviour in 0.19 was to favour the parent baseof.html.

Full repo to test here: https://github.com/spf13/hugo/issues/3505. Case #5 is the one that fails.