Hi, the challenge I’m facing is getting the value of params
from within a JS file, as specified in this doc:
https://gohugo.io/hugo-pipes/js/#option
I’m able to retrieve the values, however, the values I get do not match the context of the current page.
.html file
{{ $root := "home" }}
{{ if not .Page.IsHome }}
{{ $root = .Page.RelPermalink | replaceRE "/" "" }}
{{ end }}
{{ $params = dict "rootId" $root "someArg" "some arg value" "pageSections" .Params.page_sections }}
<div style="color: red;">{{ $params.rootId }}</div> <!-- THIS DISPLAYS CORRECTLY -->
{{ $js := resources.Get "js/jsx-components/PageLayout.jsx" | js.Build (dict "params" $params "shims" $shims "defines" $defines) }}
<script src="{{ $js.RelPermalink }}" defer></script>
From PageLayout.jsx
import * as params from '@params';
console.log({params}); // THIS DOES NOT DISPLAY CORRECTLY. IT WILL SHOW RESPECTIVE VALUES FOR A DIFFERENT PAGE
I’ve attempted to follow a similar pattern as displayed here with some modifications.
This is the first time using Hugo so it’s possible that I’m missing something fundamental. Any help would be appreciated. I’ve created a slimmed down repo if it helps to view the larger scope.
Created a demo repo here: GitHub - seejonlee/hugo-jsx
If you click around the nav items at the top and view the console you’ll notice the differences specified in the code snippets above.