Hello, I have a problem that I am really struggling to understand. I hope someone can give me a steer on it. I have just come back to hugo after about 12 months away from it and discovered a problem with my theme.
What’s the problem?
My iframes have all broken.
It seems to be related to upgrading from Hugo 0.115.1
to Hugo 0.135.0
.
Context
I’m a university lecturer and I have a site I developed for my students using my own custom theme.
The site includes example HTML, CSS and JavaScript code example for my students. Along with my code listings, I includes iframes which show the resulting web pages as they would see them. For example, this exercise shows how to build an animated menu with HTML and CSS. The code is introduced step by step and each step includes an iframe which shows the site as the students should see it.
The site was built last year with Hugo 0.115.1
and I recently started creating a new site with the same theme. I upgraded Hugo to 0.135.0
before starting and I was confused to find that the iframes were not working in the same way as the original site.
I tried serving the old site locally with v0.135.0
and all the iframes were broken in that also. From this, I conclude that the cause seems to be the upgrade from Hugo 0.115.1 to Hugo 0.135.0. I’m not sure where the issue was introduced but I’m assuming I was relying on a bug of some kind which may have now been fixed?
How did it work?
I have a fairly standard shortcode in my theme like this:
<iframe loading="lazy" {{- range $k, $v :=.Params -}} {{- (printf " %s=%q" $k $v) | safeHTMLAttr -}} {{- end -}}>
{{- .Inner | .Page.RenderString -}}
</iframe>
The iframes are included like this.
{{<iframe src="examples/step-01" width="360" height="640">}}{{</iframe>}}
The page bundle includes the code for all the steps in the exercise under a folder (in this case examples
).
content/
├── the-section/
│ ├── the-page/
│ │ ├── examples/ <-- This contains example code
│ │ │ ├── step-01/ <-- These folders are to be presented within iframes
│ │ │ │ ├─ style.css
│ │ │ │ └─ index.html
│ │ │ ├── step-02/
│ │ │ │ ├─ style.css
│ │ │ │ └─ index.html
│ │ │ └── step-03/
│ │ │ ├─ style.css
│ │ │ └─ index.html
│ │ └── index.md <-- This is where I include iframes within the content
│ ├── another-page/
│ │ └── index.md
│ └── _index.md
└── _index.md
I need the iframes to display the HTML with linked CSS and JavaScript.
The code should be stored in my project as resources, not content.
I was very pleased with myself when I came up with this idea and it has demonstrably worked well in older versions of hugo.
What have I tried?
I can see its something to do with whether the example code is treated as content.
When I experiment, there are two things happening.
-
The current situation is that the content is completely ignored by the compilation process and I get a compiled 404 not found page in the iframes.
-
If I remove a folder, the examples are being treated as content and are compiled into my template. So the iframes are showing compiled pages
Neither of these is what I want.
I was wondering if there was a way to mark the content as static within my page bundle. Or perhaps I can do something more clever?
Please help!