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
@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).
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.