I’m creating a single paged portfolio website and I’m wondering how I can set it up so that I only need to define each html block once. Currently I’m having to rewrite my html blocks for however many projects or skills I have. I want to have it so that I only need 1 html block and for each project or skill, I can create its own .md file in content
Wait but if I use partials don’t they all go into the layouts folder? In that case, I’d have all my website content in the layouts folder and my content folder would be empty (like it is right now). Is this bad practice?
<h2>Skills</h2>
{{ range where .Site.RegularPages "Type" "skills" }}
{{ .Render "summary" }}
{{ end }}
<h2>Projects</h2>
{{ range where .Site.RegularPages "Type" "projects" }}
{{ .Render "summary" }}
{{ end }}
layouts/projects/summary.html
<article class="project">
<h3>{{ .Title }}</h3>
<p>Foo: {{ .Params.foo }}</p>
{{ with .Resources.GetMatch "*.jpg" }}
{{ with .Resize "300x webp"}}
<img src="{{ .RelPermalink }}" width="{{ .Width}}" height="{{ .Height }}">
{{ end }}
{{ end }}
{{ .Content }}
</article>
layouts/skills/summary.html
<article class="skill">
<h3>{{ .Title }}</h3>
<p>Bar: {{ .Params.bar }}</p>
{{ with .Resources.GetMatch "*.jpg" }}
{{ with .Resize "300x webp"}}
<img src="{{ .RelPermalink }}" width="{{ .Width}}" height="{{ .Height }}">
{{ end }}
{{ end }}
{{ .Content }}
</article>
try it
git clone --single-branch -b hugo-forum-topic-34523 https://github.com/jmooring/hugo-testing hugo-forum-topic-34523
cd hugo-forum-topic-34523
hugo server
Thanks so much, this is exactly what I was looking for. I really appreciate this!
Yeah I think I may need to go through Hugo tutorials again, because I didn’t realize you could do things like this.
So correct me if I’m wrong, but in this case, the list.html and single.html files don’t actually do anything because there is just 1 main home page (index.html). Is this correct?