Logic in markdown?

Is it possible to use logic in markdown content files? I use

{{ range $tab := .Site.Data.configuration }}
....
{{ end }}

in one of my markdown files, but that just shows up literally rather than looping through the data var to create the content.

Nope, you can’t use “logic” (or let’s call it go functions). What you can do is look at the shortcode documentation and create a shortcode. That is usable in markdown files.

1 Like

Will headings generated by shortcodes show up in TOCs?

Doesn’t look like it does… can I push stuff into the TOC from my shortcode?

Yes, if you use this shortcode syntax:

{{%
1 Like

I must be doing something wrong… when I use {{% shortcode %}} instead of {{< shortcode >}}, the shortcode HTML shows up as raw HTML (<h3>...</h3>) instead of as rendered HTML.

Could you be more specific and give an example of what you mean by raw vs rendered?

Instead of some text

I’m seeing <b>some text</b>

This is expected, no? (And are you viewing the html in a text editor or a browser?)

I mean <b>some text</b> is showing up in the browser. Using {{% ... %}} wraps the output from the shortcode in <pre> tags where {{< ... >}} does not.

my shortcode currently looks like this:

{{ range $tab := .Site.Data.configuration }}
  
  <h2>{{ $tab.name | markdownify | safeHTML }}</h2>

  {{ $tab.description | markdownify | safeHTML }}

  {{ range $pref, $details := $tab.preferences }}

    <h3>{{ $pref | markdownify | safeHTML }}</h3>

    <p>default: <code>{{ $details.default | markdownify | safeHTML }}</code></p>

    <p>{{ $details.description | markdownify | safeHTML }}</p>

    {{ with $details.options }}
      <p>Options:

      {{ range $option := . }}
        <li>{{ $option | markdownify | safeHTML }}</li>
      {{ end }}
      </p>
    {{ end }}

  {{ end }}

{{ end }}

Wait – the shortcodes have extension .html but are expected to hold markdown?

If I change everything to markdown in the shortcode (even though it ends in .html), it renders exactly as I wanted, TOC and all.

Hmm. I’ll investigate once back at my laptop, unless others help ya.

I don’t see <b> tags in your shortcode.

Sorry for the confusion, that was meant to be an example – from the shortcode I posted, everything in angle brackets (<p>, <h3>, <h2>, <li>) shows up verbatim because it was indented, and the markdown processor changed that into a <pre> block. I now have (in the same .html file):

{{ range $tab := .Site.Data.configuration }}


## {{ $tab.name }}

{{ $tab.description }}

  {{ range $pref, $details := $tab.preferences }}

#### {{ $pref }}

default: `{{ $details.default }}`

{{ $details.description }}

{{ with $details.options }}
Options:

  {{ range $option := . }}
* {{ $option }}
  {{ end }}
{{ end }}

{{ end }}

{{ end }}

and that works when I call it with {{% ... %}}.

I see. Can you share your full project? Or create a minimal reproducible example and share that?

My full project is at https://github.com/retorquere/zotero-better-bibtex/tree/hugo/bbt ; the page that calls the shortcode is test.md.

That link gives me a 404

I’ve since moved it to https://github.com/retorquere/zotero-better-bibtex/tree/master/site