Using *in .Content* doesn't work

I’m trying to load a js library based in a condition, if the string mermaid is present somewhere in .Content then don’t include the library, for this I use in a template:

{{ if (in .Content "mermaid")}}
<script src="https://cdnjs.cloudflare.com/ajax/libs/mermaid/8.0.0-rc.8/mermaid.min.js"></script>
{{ end }}

But when trying it with an index.md file like:

---
title: My title
---
Some text

<div class="mermaid text-center">
something
</div>

It doesn’t work, is this a bug or am I doing something wrong?
Thanks

Using Hugo Static Site Generator v0.54.0/extended linux/amd64 BuildDate: 2019-02-01T13:31:26Z

Hi there. Instead of checking .Content try it with .RawContent

1 Like

What is the expected outcome from your example, and what are you getting?

@marcanuy I assumed you meant something along the lines of “My content has the mermaid css class and when checking for that text, it should return true for this example content file.” (which when I tested locally, only worked for .RawContent as mentioned in my original reply).

But yeah as @maiki mentioned please do clarify

Sorry for the confusion but the idea was to check for the presence of the mermaid class in a page, and then load the associated JS library , i.e.: only if “mermaid” is in .Content.

This worked perfectly @zwbetz

Thank you both for your help!