Hi there, I’m new in Hugo.
I’m trying to include js scripts to shortcodes (navbar, carousel, etc in layouts/partials/navbar.html eg)
This works ok on /layouts/index.html (home), I use the script tag like this: <script src="js/mobile__menu.js"></script>
and placing the file in /static/js
But when I go to other view /contact eg I cannot see the script tag, nor in the body neither into event listeners tab in the dev tools.
I tried to move the scripts into layouts/_default/baseof.html inside body tag:
{{ with resources.Get "js/mobile__menu.js" }}
{{ if hugo.IsDevelopment }}
{{ with . | js.Build }}
<script src="{{ .RelPermalink }}"></script>
{{ end }}
{{ else }}
{{ $opts := dict "minify" true }}
{{ with . | js.Build $opts | fingerprint }}
<script src="{{ .RelPermalink }}" integrity="{{ .Data.Integrity }}" crossorigin="anonymous"></script>
{{ end }}
{{ end }}
{{ end }}
as I read in hugo docs, but it didn’t work either.
To sum up, I’ve got a scripts that only works in home, when I go to other views they dissapear. The site is multilanguage (idk if this information is relevant), thank you for reading
Include a link to the source code repository of your project, because we really need the context of seeing your templates and partials to be able to help you. It is trivial to do a quick git clone on your repo, then run hugo server in your project, to help you out. On the other hand, recreating your code from screenshots, or sort of guessing at it, is not.
If you can’t share your repository for whatever reason, consider creating a dummy repo that you can share, which reproduces the problem you’re experiencing.