HUGO

Listing links with their content and titles using a shortcode

Here is a list of links:

{{< references >}}
[Title of a link](https://www.linkone.com "Content of a link 1")
[Title of a link](https://www.linktwo.com "Content of a link 2")
[Title of a link](https://www.linkthree.com "Content of a link 3")
{{< /references >}}

How to list a group of links with their content and titles using a shortcode?

<figure>
<figcaption>References:</figcaption>
<ul>

<li><a href=""></a></li>

</ul>
</figure>

The shortcode will be similar to what we created for your previous question, but since we’re passing in markdown we need to render it to HTML with either markdownify or .Page.RenderString:

layouts/shortcodes/references.html:

<figure>
  <figcaption>References:</figcaption>
  <ul>
    {{- $line := "" -}}
    {{- range (split .Inner "\n") -}}
      {{- $line = trim . " " -}}
      {{- if gt (len $line) 0 }}
        <li>{{ $line | $.Page.RenderString }}</li>
      {{- end }}
    {{- end }}
  </ul>
</figure>
1 Like

I can’t believe how well this code works. I totally missed .RenderString function. Thank you.

1 Like