CINXE.COM
Updating a scratch pad with nested data - support - HUGO
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Updating a scratch pad with nested data - support - HUGO</title> <meta name="description" content="I’ve successfully configured Hugo with multiple output formats to render pages in different formats (e.g., multiple HTML formats, ICS for internet calendars, and JSON). This setup works great so far. However, I’m now ru&hellip;"> <meta name="generator" content="Discourse 3.4.0.beta3-dev - https://github.com/discourse/discourse version 5bf5d1335680f28a8eb65c488353be9585eed08e"> <link rel="icon" type="image/png" href="https://global.discourse-cdn.com/flex036/uploads/gohugo/optimized/2X/6/66a05218f64425b2fa59ede30c1b4b7dc1fdf5f9_2_32x32.ico"> <link rel="apple-touch-icon" type="image/png" href="https://global.discourse-cdn.com/flex036/uploads/gohugo/optimized/2X/c/c2d3414c64e766d814100b32063948e604298a70_2_180x180.png"> <meta name="theme-color" media="all" content="#0a1922"> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, user-scalable=yes, viewport-fit=cover"> <link rel="canonical" href="https://discourse.gohugo.io/t/updating-a-scratch-pad-with-nested-data/52501" /> <link rel="search" type="application/opensearchdescription+xml" href="https://discourse.gohugo.io/opensearch.xml" title="HUGO Search"> <link href="https://yyz2.discourse-cdn.com/flex036/stylesheets/color_definitions_hugo-light_1_3_09733212c5bcbf3d2262e9135364889a94410a8e.css?__ws=discourse.gohugo.io" media="all" rel="stylesheet" class="light-scheme"/> <link href="https://yyz2.discourse-cdn.com/flex036/stylesheets/desktop_d02c2ac443d5119470bb87ccc1761df2dc8dc4ce.css?__ws=discourse.gohugo.io" media="all" rel="stylesheet" data-target="desktop" /> <link href="https://yyz2.discourse-cdn.com/flex036/stylesheets/checklist_d02c2ac443d5119470bb87ccc1761df2dc8dc4ce.css?__ws=discourse.gohugo.io" media="all" rel="stylesheet" data-target="checklist" /> <link href="https://yyz2.discourse-cdn.com/flex036/stylesheets/discourse-adplugin_d02c2ac443d5119470bb87ccc1761df2dc8dc4ce.css?__ws=discourse.gohugo.io" media="all" rel="stylesheet" data-target="discourse-adplugin" /> <link href="https://yyz2.discourse-cdn.com/flex036/stylesheets/discourse-ai_d02c2ac443d5119470bb87ccc1761df2dc8dc4ce.css?__ws=discourse.gohugo.io" media="all" rel="stylesheet" data-target="discourse-ai" /> <link href="https://yyz2.discourse-cdn.com/flex036/stylesheets/discourse-akismet_d02c2ac443d5119470bb87ccc1761df2dc8dc4ce.css?__ws=discourse.gohugo.io" media="all" rel="stylesheet" data-target="discourse-akismet" /> <link href="https://yyz2.discourse-cdn.com/flex036/stylesheets/discourse-cakeday_d02c2ac443d5119470bb87ccc1761df2dc8dc4ce.css?__ws=discourse.gohugo.io" media="all" rel="stylesheet" data-target="discourse-cakeday" /> <link href="https://yyz2.discourse-cdn.com/flex036/stylesheets/discourse-details_d02c2ac443d5119470bb87ccc1761df2dc8dc4ce.css?__ws=discourse.gohugo.io" media="all" rel="stylesheet" data-target="discourse-details" /> <link href="https://yyz2.discourse-cdn.com/flex036/stylesheets/discourse-lazy-videos_d02c2ac443d5119470bb87ccc1761df2dc8dc4ce.css?__ws=discourse.gohugo.io" media="all" rel="stylesheet" data-target="discourse-lazy-videos" /> <link href="https://yyz2.discourse-cdn.com/flex036/stylesheets/discourse-local-dates_d02c2ac443d5119470bb87ccc1761df2dc8dc4ce.css?__ws=discourse.gohugo.io" media="all" rel="stylesheet" data-target="discourse-local-dates" /> <link href="https://yyz2.discourse-cdn.com/flex036/stylesheets/discourse-narrative-bot_d02c2ac443d5119470bb87ccc1761df2dc8dc4ce.css?__ws=discourse.gohugo.io" media="all" rel="stylesheet" data-target="discourse-narrative-bot" /> <link href="https://yyz2.discourse-cdn.com/flex036/stylesheets/discourse-presence_d02c2ac443d5119470bb87ccc1761df2dc8dc4ce.css?__ws=discourse.gohugo.io" media="all" rel="stylesheet" data-target="discourse-presence" /> <link href="https://yyz2.discourse-cdn.com/flex036/stylesheets/discourse-solved_d02c2ac443d5119470bb87ccc1761df2dc8dc4ce.css?__ws=discourse.gohugo.io" media="all" rel="stylesheet" data-target="discourse-solved" /> <link href="https://yyz2.discourse-cdn.com/flex036/stylesheets/footnote_d02c2ac443d5119470bb87ccc1761df2dc8dc4ce.css?__ws=discourse.gohugo.io" media="all" rel="stylesheet" data-target="footnote" /> <link href="https://yyz2.discourse-cdn.com/flex036/stylesheets/hosted-site_d02c2ac443d5119470bb87ccc1761df2dc8dc4ce.css?__ws=discourse.gohugo.io" media="all" rel="stylesheet" data-target="hosted-site" /> <link href="https://yyz2.discourse-cdn.com/flex036/stylesheets/poll_d02c2ac443d5119470bb87ccc1761df2dc8dc4ce.css?__ws=discourse.gohugo.io" media="all" rel="stylesheet" data-target="poll" /> <link href="https://yyz2.discourse-cdn.com/flex036/stylesheets/spoiler-alert_d02c2ac443d5119470bb87ccc1761df2dc8dc4ce.css?__ws=discourse.gohugo.io" media="all" rel="stylesheet" data-target="spoiler-alert" /> <link href="https://yyz2.discourse-cdn.com/flex036/stylesheets/discourse-ai_desktop_d02c2ac443d5119470bb87ccc1761df2dc8dc4ce.css?__ws=discourse.gohugo.io" media="all" rel="stylesheet" data-target="discourse-ai_desktop" /> <link href="https://yyz2.discourse-cdn.com/flex036/stylesheets/poll_desktop_d02c2ac443d5119470bb87ccc1761df2dc8dc4ce.css?__ws=discourse.gohugo.io" media="all" rel="stylesheet" data-target="poll_desktop" /> <link href="https://yyz2.discourse-cdn.com/flex036/stylesheets/desktop_theme_2_554e2f649b5332218939d027878568e9fb5cb3e9.css?__ws=discourse.gohugo.io" media="all" rel="stylesheet" data-target="desktop_theme" data-theme-id="2" data-theme-name="custom header links"/> <link href="https://yyz2.discourse-cdn.com/flex036/stylesheets/desktop_theme_3_ba320989966c049743dec43ab8cc84324bf2a254.css?__ws=discourse.gohugo.io" media="all" rel="stylesheet" data-target="desktop_theme" data-theme-id="3" data-theme-name="hugo light"/> <meta id="data-ga-universal-analytics" data-tracking-code="UA-7131036-7" data-json="{"cookieDomain":"auto"}" data-auto-link-domains=""> <script async src="https://www.googletagmanager.com/gtag/js?id=UA-7131036-7" nonce="A0HhKfRTGbnfy1MsLW5V73ynN"></script> <script defer src="https://global.discourse-cdn.com/flex036/assets/google-universal-analytics-v4-e154af4adb3c483a3aba7f9a7229b8881cdc5cf369290923d965a2ad30163ae8.gz.js" data-discourse-entrypoint="google-universal-analytics-v4" nonce="A0HhKfRTGbnfy1MsLW5V73ynN"></script> <link rel="alternate nofollow" type="application/rss+xml" title="RSS feed of 'Updating a scratch pad with nested data'" href="https://discourse.gohugo.io/t/updating-a-scratch-pad-with-nested-data/52501.rss" /> <meta property="og:site_name" content="HUGO" /> <meta property="og:type" content="website" /> <meta name="twitter:card" content="summary" /> <meta name="twitter:image" content="https://global.discourse-cdn.com/flex036/uploads/gohugo/original/2X/b/b91c8ab3a3c1c8679127cf049b46fa919e9e0e5c.png" /> <meta property="og:image" content="https://global.discourse-cdn.com/flex036/uploads/gohugo/original/2X/b/b91c8ab3a3c1c8679127cf049b46fa919e9e0e5c.png" /> <meta property="og:url" content="https://discourse.gohugo.io/t/updating-a-scratch-pad-with-nested-data/52501" /> <meta name="twitter:url" content="https://discourse.gohugo.io/t/updating-a-scratch-pad-with-nested-data/52501" /> <meta property="og:title" content="Updating a scratch pad with nested data" /> <meta name="twitter:title" content="Updating a scratch pad with nested data" /> <meta property="og:description" content="I’ve successfully configured Hugo with multiple output formats to render pages in different formats (e.g., multiple HTML formats, ICS for internet calendars, and JSON). This setup works great so far. However, I’m now running into a challenge: I need Hugo to dynamically search for and resize images based on speaker names provided in the page’s front matter data. While I’ve got a working solution for the HTML template, I’m struggling to integrate this functionality into the JSON output. Current ..." /> <meta name="twitter:description" content="I’ve successfully configured Hugo with multiple output formats to render pages in different formats (e.g., multiple HTML formats, ICS for internet calendars, and JSON). This setup works great so far. However, I’m now running into a challenge: I need Hugo to dynamically search for and resize images based on speaker names provided in the page’s front matter data. While I’ve got a working solution for the HTML template, I’m struggling to integrate this functionality into the JSON output. Current ..." /> <meta property="og:article:section" content="support" /> <meta property="og:article:section:color" content="652D90" /> <meta name="twitter:label1" value="Reading time" /> <meta name="twitter:data1" value="2 mins 🕑" /> <meta name="twitter:label2" value="Likes" /> <meta name="twitter:data2" value="1 ❤" /> <meta property="article:published_time" content="2024-11-22T10:57:18+00:00" /> <meta property="og:ignore_canonical" content="true" /> <script type="application/ld+json">{"@context":"http://schema.org","@type":"QAPage","name":"Updating a scratch pad with nested data","mainEntity":{"@type":"Question","name":"Updating a scratch pad with nested data","text":"I’ve successfully configured Hugo with multiple output formats to render pages in different formats (e.g., multiple HTML formats, ICS for internet calendars, and JSON). This setup works great so far.\n\nHowever, I’m now running into a challenge: I need Hugo to dynamically search for and resize images …","upvoteCount":0,"answerCount":1,"datePublished":"2024-11-22T10:57:18.688Z","author":{"@type":"Person","name":"vanbroup","url":"https://discourse.gohugo.io/u/vanbroup"},"acceptedAnswer":{"@type":"Answer","text":"Front matter:\n\n---\n\ntitle: example\n\nparams:\n\ndata:\n\ncolors:\n\n- red\n\n- blue\n\n- green\n\n---\n\nTemplate:\n\n{{ $s := newScratch }}\n\n{{ $s.Set "data" .Page.Params.data }}\n\n{{ $s.Set "data" (merge ($s.Get "data") (dict "name" "test")) }}\n\n<pre>{{ jsonify (dict "indent" " ") $s.Values }}</pre>\n\n…","upvoteCount":0,"datePublished":"2024-11-22T16:20:27.453Z","url":"https://discourse.gohugo.io/t/updating-a-scratch-pad-with-nested-data/52501/2","author":{"@type":"Person","name":"jmooring","url":"https://discourse.gohugo.io/u/jmooring"}}}}</script> </head> <body class="crawler browser-update"> <script defer="" src="https://yyz2.discourse-cdn.com/flex036/theme-javascripts/417061e7eee24be4fb6a457975f0dce96a82d9e6.js?__ws=discourse.gohugo.io" data-theme-id="5" nonce="A0HhKfRTGbnfy1MsLW5V73ynN"></script> <header> <a href="/"> HUGO </a> </header> <div id="main-outlet" class="wrap" role="main"> <div id="topic-title"> <h1> <a href="/t/updating-a-scratch-pad-with-nested-data/52501">Updating a scratch pad with nested data</a> </h1> <div class="topic-category" itemscope itemtype="http://schema.org/BreadcrumbList"> <span itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"> <a href="/c/support/34" class="badge-wrapper bullet" itemprop="item"> <span class='badge-category-bg' style='background-color: #652D90'></span> <span class='badge-category clear-badge'> <span class='category-name' itemprop='name'>support</span> </span> </a> <meta itemprop="position" content="1" /> </span> </div> </div> <div itemscope itemtype='http://schema.org/DiscussionForumPosting'> <meta itemprop='headline' content='Updating a scratch pad with nested data'> <link itemprop='url' href='https://discourse.gohugo.io/t/updating-a-scratch-pad-with-nested-data/52501'> <meta itemprop='datePublished' content='2024-11-22T10:57:18Z'> <meta itemprop='articleSection' content='support'> <meta itemprop='keywords' content=''> <div itemprop='publisher' itemscope itemtype="http://schema.org/Organization"> <meta itemprop='name' content='HUGO'> </div> <div id='post_1' class='topic-body crawler-post'> <div class='crawler-post-meta'> <span class="creator" itemprop="author" itemscope itemtype="http://schema.org/Person"> <a itemprop="url" href='https://discourse.gohugo.io/u/vanbroup'><span itemprop='name'>vanbroup</span></a> </span> <link itemprop="mainEntityOfPage" href="https://discourse.gohugo.io/t/updating-a-scratch-pad-with-nested-data/52501"> <span class="crawler-post-infos"> <time datetime='2024-11-22T10:57:18Z' class='post-time'> November 22, 2024, 10:57am </time> <meta itemprop='dateModified' content='2024-11-22T11:02:58Z'> <span itemprop='position'>1</span> </span> </div> <div class='post' itemprop='text'> <p>I’ve successfully configured Hugo with multiple output formats to render pages in different formats (e.g., multiple HTML formats, ICS for internet calendars, and JSON). This setup works great so far.</p> <p>However, I’m now running into a challenge: I need Hugo to dynamically search for and resize images based on speaker names provided in the page’s front matter data. While I’ve got a working solution for the HTML template, I’m struggling to integrate this functionality into the JSON output.</p> <h3><a name="p-171569-current-html-template-1" class="anchor" href="#p-171569-current-html-template-1"></a>Current HTML Template</h3> <p>Here’s the working template that locates and resizes images based on the speaker’s name:</p> <pre><code class="lang-auto">{{ $headshot := (printf "headshots/%s.*" (default (.name | urlize | safeURL) .headshot)) -}} {{ $img := $.Page.Resources.GetMatch $headshot }} {{ $title := (printf "%s - %s" .name .title) }} {{ with $img }} {{ $img = $img.Resize "x150" }} {{ return $img.RelPermalink }} {{ end }} </code></pre> <p>This looks for an image file named <code>headshots/speaker-one.jpg</code> and generates a relative permalink to the resized image. It also allows manual overrides using the <code>.headshot</code> variable for filenames with diacritics or other complexities.</p> <h3><a name="p-171569-the-json-output-template-2" class="anchor" href="#p-171569-the-json-output-template-2"></a>The JSON Output Template</h3> <p>Currently, my JSON output template is straightforward:</p> <pre><code class="lang-auto">{{- .Page.Params.data | jsonify -}} </code></pre> <p>Which results in:</p> <pre data-code-wrap="json"><code class="lang-json">{ "name": "Event name", "speakers": [ { "name": "Speaker One", "title": "Expert at Org Inc." }, ... ] } </code></pre> <p>When we can’t modify the data, our template becomes significantly more complex and error-prone, as it would mean reconstructing the entire JSON output just to add the resized images.</p> <h3><a name="p-171569-front-matter-example-3" class="anchor" href="#p-171569-front-matter-example-3"></a>Front Matter Example</h3> <p>Here’s an example of my page’s front matter:</p> <pre data-code-wrap="yaml"><code class="lang-yaml">outputs: - html - event-data - event-overlays - event-session - event-agenda data: name: Event name timezone: America/Chicago speakers: - name: Speaker One # Locate image based on this name title: Expert at Org Inc. - name: Speaker Fifty title: Expert at Org Ltd. </code></pre> <p>Some speakers might not have associated headshots, and in such cases, the output should gracefully handle missing images.</p> <h3><a name="p-171569-desired-scratch-pad-data-4" class="anchor" href="#p-171569-desired-scratch-pad-data-4"></a>Desired scratch pad data</h3> <p>I want to enhance the <code>data.speakers</code> section by adding resized images for each speaker, resulting in something like this:</p> <pre data-code-wrap="yaml"><code class="lang-yaml">data: speakers: - name: Speaker One title: Expert at Org Inc. headshots: "150x": "./speakers/speaker-one-150x.jpg" "500x": "./speakers/speaker-one-500x.jpg" - name: Speaker Fifty title: Expert at Org Ltd. </code></pre> <h3><a name="p-171569-scratchpad-issue-5" class="anchor" href="#p-171569-scratchpad-issue-5"></a>Scratchpad Issue</h3> <p>I attempted to use Hugo’s scratch pad to dynamically update the <code>data</code> object, but I’m running into issues. For example, the following simple example doesn’t update the <code>data.name</code> value as expected:</p> <pre><code class="lang-auto">{{- $s := newScratch -}} {{- $s.Set "data" .Page.Params.data -}} {{- $s.Set "data.name" "test" -}} {{- $s.Get "data" | jsonify -}} </code></pre> <p>same for:</p> <pre><code class="lang-auto">{{- $s := newScratch -}} {{- $s.Set "data" .Page.Params.data -}} {{- $s.SetInMap "data" "name" "test" -}} {{- $s.Get "data" | jsonify -}} </code></pre> <p>but this ‘works’ (overwrite the entire object):</p> <pre><code class="lang-auto">{{- $s := newScratch -}} {{- $s.Set "data" .Page.Params.data -}} {{- $s.Set "data" "test" -}} {{- $s.Get "data" | jsonify -}} </code></pre> <h3><a name="p-171569-questions-6" class="anchor" href="#p-171569-questions-6"></a>Questions</h3> <ol> <li>Can the scratch pad or store handle nested data to begin with?</li> <li>Is there a better approach than the scratchpad to achieve this transformation?</li> </ol> <p>Any advice or insights would be greatly appreciated. Thanks in advance for your help!</p> </div> <div itemprop="interactionStatistic" itemscope itemtype="http://schema.org/InteractionCounter"> <meta itemprop="interactionType" content="http://schema.org/LikeAction"/> <meta itemprop="userInteractionCount" content="0" /> <span class='post-likes'></span> </div> </div> <div id='post_2' itemprop='comment' itemscope itemtype='http://schema.org/Comment' class='topic-body crawler-post'> <div class='crawler-post-meta'> <span class="creator" itemprop="author" itemscope itemtype="http://schema.org/Person"> <a itemprop="url" href='https://discourse.gohugo.io/u/jmooring'><span itemprop='name'>jmooring</span></a> </span> <span class="crawler-post-infos"> <time itemprop='datePublished' datetime='2024-11-22T16:20:27Z' class='post-time'> November 22, 2024, 4:20pm </time> <meta itemprop='dateModified' content='2024-11-22T16:24:45Z'> <span itemprop='position'>2</span> </span> </div> <div class='post' itemprop='text'> <p>Front matter:</p> <pre><code class="lang-plaintext">--- title: example params: data: colors: - red - blue - green --- </code></pre> <p>Template:</p> <pre><code class="lang-plaintext">{{ $s := newScratch }} {{ $s.Set "data" .Page.Params.data }} {{ $s.Set "data" (merge ($s.Get "data") (dict "name" "test")) }} <pre>{{ jsonify (dict "indent" " ") $s.Values }}</pre> </code></pre> <p>Result:</p> <pre><code class="lang-plaintext">{ "data": { "colors": [ "red", "blue", "green" ], "name": "test" } } </code></pre> <p>Notes:</p> <ul> <li>In the first part of your example, there’s no need to pass the value through the <code>safeHTML</code> function… you’re not rendering the value.</li> <li>It’s not clear to me why you’re using a local scratch for this. Seems like it would be easier to use the <code>merge</code> function.</li> </ul> </div> <div itemprop="interactionStatistic" itemscope itemtype="http://schema.org/InteractionCounter"> <meta itemprop="interactionType" content="http://schema.org/LikeAction"/> <meta itemprop="userInteractionCount" content="0" /> <span class='post-likes'></span> </div> </div> <div id='post_3' itemprop='comment' itemscope itemtype='http://schema.org/Comment' class='topic-body crawler-post'> <div class='crawler-post-meta'> <span class="creator" itemprop="author" itemscope itemtype="http://schema.org/Person"> <a itemprop="url" href='https://discourse.gohugo.io/u/irkode'><span itemprop='name'>irkode</span></a> </span> <span class="crawler-post-infos"> <time itemprop='datePublished' datetime='2024-11-22T16:39:46Z' class='post-time'> November 22, 2024, 4:39pm </time> <meta itemprop='dateModified' content='2024-11-22T18:14:47Z'> <span itemprop='position'>3</span> </span> </div> <div class='post' itemprop='text'> <p>If I got that right our OP</p> <ul> <li>has a list of maps in the speaker attribute and</li> <li>wants to add a new field to each map with a calculated values</li> <li>has two (or more) output formats that should use the one time calculated data</li> </ul> <h4><a name="p-171576-input-1" class="anchor" href="#p-171576-input-1"></a>input</h4> <pre data-code-wrap="yaml"><code class="lang-yaml">params: data: name: Event name timezone: America/Chicago speakers: - name: Speaker One title: Expert at Org Inc. - name: Speaker Fifty title: Expert at Org Ltd. </code></pre> <h4><a name="p-171576-output-2" class="anchor" href="#p-171576-output-2"></a>output:</h4> <pre data-code-wrap="yaml"><code class="lang-yaml">event: Event name speakers: - headshot: "calculated image: Speaker One-img" name: Speaker One title: Expert at Org Inc. - headshot: "calculated image: Speaker Fifty-img" name: Speaker Fifty title: Expert at Org Ltd. zone: America/Chicago </code></pre> <h3><a name="p-171576-suggestion-3" class="anchor" href="#p-171576-suggestion-3"></a>suggestion:</h3> <p>I’m pretty sure <a class="mention" href="/u/jmooring">@jmooring</a> will have a cleaner approach or even tell s me that his version will handle that… but I wanted to give it a try</p> <p>I would use variables and a partial to generate the event data.</p> <h4><a name="p-171576-page-frontmatter-4" class="anchor" href="#p-171576-page-frontmatter-4"></a>page frontmatter:</h4> <p>i moved the data into the params section cause custom toplevel fields are deprecated</p> <pre data-code-wrap="yaml"><code class="lang-yaml">title: Event One date: 2023-01-01T15:00:00.000Z draft: false params: data: name: Event name timezone: America/Chicago speakers: - name: Speaker One title: Expert at Org Inc. - name: Speaker Fifty title: Expert at Org Ltd. </code></pre> <h4><a name="p-171576-event-page-template-5" class="anchor" href="#p-171576-event-page-template-5"></a>event page template:</h4> <pre><code class="lang-auto">{{ define "main" }} # prepare the data {{ $eventdata := partialCached "speakers" .Params.data }} # print the data to the page {{ highlight (debug.Dump $eventdata) "JSON" }} {{ end }} </code></pre> <h4><a name="p-171576-event-json-template-6" class="anchor" href="#p-171576-event-json-template-6"></a>event json template:</h4> <pre><code class="lang-auto"> # prepare the data {{ $eventdata := partialCached "speakers" .Params.data }} # dump out json data to the json file {{ debug.Dump $eventdata }} </code></pre> <h3><a name="p-171576-the-speakers-partial-7" class="anchor" href="#p-171576-the-speakers-partial-7"></a>the speakers partial</h3> <pre><code class="lang-auto">{{ $speakers := slice }} {{ range .speakers }} {{ $speakers = $speakers | append (dict "name" .name "title" .title "headshot" (printf "calculated image: %s-img" .name )) }} {{ end }} {{ return dict "event" .name "zone" .timezone "speakers" $speakers }} </code></pre> <p>hint: don’t use debug.Dump in real life cause it is internal and may change without anouncement</p> <p>used as cached partial to reduce duplicate rendering. If you have speakers talking a lot, maybe have one cached partial per speaker inside the loop or prerender all speakers seperately</p> <p>and ofc you may save the results to a scratch or store make sure to read the docs carefully then.</p> </div> <div itemprop="interactionStatistic" itemscope itemtype="http://schema.org/InteractionCounter"> <meta itemprop="interactionType" content="http://schema.org/LikeAction"/> <meta itemprop="userInteractionCount" content="0" /> <span class='post-likes'></span> </div> </div> <div id='post_4' itemprop='comment' itemscope itemtype='http://schema.org/Comment' class='topic-body crawler-post'> <div class='crawler-post-meta'> <span class="creator" itemprop="author" itemscope itemtype="http://schema.org/Person"> <a itemprop="url" href='https://discourse.gohugo.io/u/vanbroup'><span itemprop='name'>vanbroup</span></a> </span> <span class="crawler-post-infos"> <time itemprop='datePublished' datetime='2024-11-22T19:14:26Z' class='post-time'> November 22, 2024, 7:14pm </time> <meta itemprop='dateModified' content='2024-11-22T19:14:26Z'> <span itemprop='position'>4</span> </span> </div> <div class='post' itemprop='text'> <p>A combination of append amd merge did the job indeed:</p> <pre><code class="lang-auto">{{- $speakers := slice -}} {{- range .Page.Params.data.speakers -}} {{- $speaker := . -}} {{- $headshot := (printf "speakers/%s.*" (default (.name | urlize | safeURL) .headshot)) -}} {{- with $.Page.Resources.GetMatch $headshot -}} {{ $x150 := .Resize "x150" }} {{ $x250 := .Resize "x250" }} {{ $x600 := .Resize "x600" }} {{- $speakers = $speakers | append (merge $speaker (dict "headshot" (dict "x150" $x150.Permalink "x250" $x250.Permalink "x600" $x600.Permalink ))) -}} {{- else -}} {{- $speakers = $speakers | append $speaker -}} {{- end -}} {{- end -}} {{- $data := merge .Page.Params.data (dict "speakers" $speakers) -}} {{- $data | jsonify -}} </code></pre> <p>Now we can simply move this into a cached partial and we are done <img src="https://emoji.discourse-cdn.com/twitter/slight_smile.png?v=12" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p> <p>Thanks!</p> </div> <div itemprop="interactionStatistic" itemscope itemtype="http://schema.org/InteractionCounter"> <meta itemprop="interactionType" content="http://schema.org/LikeAction"/> <meta itemprop="userInteractionCount" content="1" /> <span class='post-likes'>1 Like</span> </div> </div> <div id='post_5' itemprop='comment' itemscope itemtype='http://schema.org/Comment' class='topic-body crawler-post'> <div class='crawler-post-meta'> <span class="creator" itemprop="author" itemscope itemtype="http://schema.org/Person"> <a itemprop="url" href='https://discourse.gohugo.io/u/system'><span itemprop='name'>system</span></a> Closed </span> <span class="crawler-post-infos"> <time itemprop='datePublished' datetime='2024-11-24T19:14:51Z' class='post-time'> November 24, 2024, 7:14pm </time> <meta itemprop='dateModified' content='2024-11-24T19:14:51Z'> <span itemprop='position'>5</span> </span> </div> <div class='post' itemprop='text'> <p>This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.</p> </div> <div itemprop="interactionStatistic" itemscope itemtype="http://schema.org/InteractionCounter"> <meta itemprop="interactionType" content="http://schema.org/LikeAction"/> <meta itemprop="userInteractionCount" content="0" /> <span class='post-likes'></span> </div> </div> </div> <div id="related-topics" class="more-topics__list " role="complementary" aria-labelledby="related-topics-title"> <h3 id="related-topics-title" class="more-topics__list-title"> Related topics </h3> <div class="topic-list-container" itemscope itemtype='http://schema.org/ItemList'> <meta itemprop='itemListOrder' content='http://schema.org/ItemListOrderDescending'> <table class='topic-list'> <thead> <tr> <th>Topic</th> <th></th> <th class="replies">Replies</th> <th class="views">Views</th> <th>Activity</th> </tr> </thead> <tbody> <tr class="topic-list-item" id="topic-list-item-10214"> <td class="main-link" itemprop='itemListElement' itemscope itemtype='http://schema.org/ListItem'> <meta itemprop='position' content='1'> <span class="link-top-line"> <a itemprop='url' href='https://discourse.gohugo.io/t/output-format-url-access/10214' class='title raw-link raw-topic-link'>Output format URL access</a> </span> <div class="link-bottom-line"> <a href='/c/support/34' class='badge-wrapper bullet'> <span class='badge-category-bg' style='background-color: #652D90'></span> <span class='badge-category clear-badge'> <span class='category-name'>support</span> </span> </a> <div class="discourse-tags"> </div> </div> </td> <td class="replies"> <span class='posts' title='posts'>14</span> </td> <td class="views"> <span class='views' title='views'>1156</span> </td> <td> February 2, 2018 </td> </tr> <tr class="topic-list-item" id="topic-list-item-25503"> <td class="main-link" itemprop='itemListElement' itemscope itemtype='http://schema.org/ListItem'> <meta itemprop='position' content='2'> <span class="link-top-line"> <a itemprop='url' href='https://discourse.gohugo.io/t/output-nested-json/25503' class='title raw-link raw-topic-link'>Output Nested JSON</a> </span> <div class="link-bottom-line"> <a href='/c/support/34' class='badge-wrapper bullet'> <span class='badge-category-bg' style='background-color: #652D90'></span> <span class='badge-category clear-badge'> <span class='category-name'>support</span> </span> </a> <div class="discourse-tags"> </div> </div> </td> <td class="replies"> <span class='posts' title='posts'>4</span> </td> <td class="views"> <span class='views' title='views'>713</span> </td> <td> May 16, 2020 </td> </tr> <tr class="topic-list-item" id="topic-list-item-27284"> <td class="main-link" itemprop='itemListElement' itemscope itemtype='http://schema.org/ListItem'> <meta itemprop='position' content='3'> <span class="link-top-line"> <a itemprop='url' href='https://discourse.gohugo.io/t/json-output-uses-the-wrong-template/27284' class='title raw-link raw-topic-link'>JSON output uses the wrong template</a> </span> <div class="link-bottom-line"> <a href='/c/support/34' class='badge-wrapper bullet'> <span class='badge-category-bg' style='background-color: #652D90'></span> <span class='badge-category clear-badge'> <span class='category-name'>support</span> </span> </a> <div class="discourse-tags"> </div> </div> </td> <td class="replies"> <span class='posts' title='posts'>10</span> </td> <td class="views"> <span class='views' title='views'>851</span> </td> <td> March 23, 2021 </td> </tr> <tr class="topic-list-item" id="topic-list-item-17640"> <td class="main-link" itemprop='itemListElement' itemscope itemtype='http://schema.org/ListItem'> <meta itemprop='position' content='4'> <span class="link-top-line"> <a itemprop='url' href='https://discourse.gohugo.io/t/reusing-the-rendered-custom-output-format-in-template-files/17640' class='title raw-link raw-topic-link'>Reusing the rendered custom output format in template files</a> </span> <div class="link-bottom-line"> <a href='/c/support/34' class='badge-wrapper bullet'> <span class='badge-category-bg' style='background-color: #652D90'></span> <span class='badge-category clear-badge'> <span class='category-name'>support</span> </span> </a> <div class="discourse-tags"> </div> </div> </td> <td class="replies"> <span class='posts' title='posts'>6</span> </td> <td class="views"> <span class='views' title='views'>456</span> </td> <td> March 20, 2019 </td> </tr> <tr class="topic-list-item" id="topic-list-item-26813"> <td class="main-link" itemprop='itemListElement' itemscope itemtype='http://schema.org/ListItem'> <meta itemprop='position' content='5'> <span class="link-top-line"> <a itemprop='url' href='https://discourse.gohugo.io/t/access-resized-image-file-names-externally/26813' class='title raw-link raw-topic-link'>Access resized image file names externally</a> </span> <div class="link-bottom-line"> <div class="discourse-tags"> </div> </div> </td> <td class="replies"> <span class='posts' title='posts'>3</span> </td> <td class="views"> <span class='views' title='views'>574</span> </td> <td> July 11, 2020 </td> </tr> </tbody> </table> </div> </div> </div> <footer class="container wrap"> <nav class='crawler-nav'> <ul> <li itemscope itemtype='http://schema.org/SiteNavigationElement'> <span itemprop='name'> <a href='/' itemprop="url">Home </a> </span> </li> <li itemscope itemtype='http://schema.org/SiteNavigationElement'> <span itemprop='name'> <a href='/categories' itemprop="url">Categories </a> </span> </li> <li itemscope itemtype='http://schema.org/SiteNavigationElement'> <span itemprop='name'> <a href='/guidelines' itemprop="url">Guidelines </a> </span> </li> <li itemscope itemtype='http://schema.org/SiteNavigationElement'> <span itemprop='name'> <a href='/tos' itemprop="url">Terms of Service </a> </span> </li> <li itemscope itemtype='http://schema.org/SiteNavigationElement'> <span itemprop='name'> <a href='/privacy' itemprop="url">Privacy Policy </a> </span> </li> </ul> </nav> <p class='powered-by-link'>Powered by <a href="https://www.discourse.org">Discourse</a>, best viewed with JavaScript enabled</p> </footer> <div class="buorg"><div>Unfortunately, <a href="https://www.discourse.org/faq/#browser">your browser is unsupported</a>. Please <a href="https://browsehappy.com">switch to a supported browser</a> to view rich content, log in and reply.</div></div> </body> </html>