How can I load jquery to specific *.md pages?

How can I load this jquery link in the head of two *.md pages?

script link:
<script src=""></script>

A conditional load for the pages /faq/ and /de/faq/. Nothing found in the docs onfortunately.

The shortcode etc. runs totally fine the way I wanted. However, I load jquery from the baseof.html, so it’s on all webpages. (I am aware that I can manage to hardcode two pages after build :sunglasses:)

In baseof.html wrap the jQuery script in a condition.

For example

{{ if in .RelPermalink "faq" }}
<--- jQuery script --->
{{ end }}

Alternatively you can set a front matter parameter in the content files whose output is meant to include jQuery.


jquery = true

And then in baseof.html use one of the following conditions:

{{ with .Params.jquery }} {{/* checks if the parameter exists */}}
{{ if eq .Params.jquery true }} {{/* checks if the boolean value of the parameter is set to true */}}
<--- jQuery script --->
{{ end }}
1 Like

Thank you! I went for the IMHO safer “front matter” method and it works perfectly, with one tiny change: for me I guess it should be jquery: true

I will use that method probably quite a lot.

This said, the docs are quite cryptic and hard to understand. They don’t look always complete to me and they certainly lack hugo examples. I quite like how has their reference command pages, a command, some references, then some examples - and after that user examples.

Example: PHP: explode - Manual

I believe this would help many newcomers quite a bit.

1 Like

The example I gave was in TOML. You are using YAML. Both are supported front matter formats in Hugo.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.