metzCY
April 9, 2019, 11:30pm
1
Hi-
Learning shortcodes, built in and documented simple examples are fine. Looking thru this theme: https://themes.gohugo.io/hugo-hero-theme/ and came across the following shortcode that I just can’t parse. Or more specifically how to invoke with the correct positional parameters in an .md file. Have tried {{<bundle-content “foo” “bar”>}} but can’t figure out foo and bar parameters.
Looks like it is retrieving a specific bundle (.Get 0) and then the first match from that bundle based on the second variable (.Get 1)?
{{ $bundle := .Get 0 }}
{{ $match := .Get 1 }}
{{ $page := .Page.Site.GetPage $bundle }}
{{ $page }}
{{ with $page }}
{{ $resource := $page.Resources.GetMatch (printf "**%s*" $match ) }}
{{ with $resource }}
<h3>Resource in shortcode</h3>
<ul>
<li>Title: {{ .Title }}</li>
<li>Content: {{ .Content }}</li>
<li>Summary: {{ .Summary }}</li>
</ul>
{{ end }}
{{ end }}
Been poring over the doc including this very good writeup.
In this article we'll cover Hugo 0.32's Page Resources and its impact on the way we structure our content folders, what methods and properties it offers, how to use it in our templates and markdown and finally its newly metadata logic!
Any guidance would be great.
-cm
Hi,
I’m guessing :
since they use .GetPage
on $bundle
(ie .Get 0
), it’s probably a page bundle like content/some-bundle/
.
they use .GetMatch
on $match
(ie .Get 1
), so that is probably a resource inside $bundle
.
So to use would probably look like {{< bundle-content "some-bundle" "some-resource" >}}
There should be a link to the theme author’s git repo on the theme page you link to, you might want to ask them directly as well.
1 Like
metzCY
April 10, 2019, 6:00pm
3
located example under content/pages/about/index.md that looks like this:
title: 'About'
date: 2018-12-06T09:29:16+10:00
layout: 'aboutlayout'
heroHeading: 'About Us'
heroSubHeading: "Established in 1985, we're a team of advisors that puts your business first."
heroBackground: 'https://source.unsplash.com/sO-JmQj95ec/1600x1000'
---
<div>
{{< content-strip-left "/pages/about" "content1" >}}
</div>
<div>
{{< content-strip-right "/pages/about" "content2" >}}
</div>
<div>
{{< content-strip-center "/pages/about" "content3" >}}
</div>
pages/about is the bundle and the content*.md are the files in the bundle, all under content/
And the content-strip** shortcodes are contained in layouts/shortcodes.
All cleared up. Thanks!