HUGO

Listing links using a shortcode

Let’s say I have a bunch of links to be used as references.

How to range links using a shortcode?

{{< references “https://linkone.com” “https://linktwo.com” “https://linkthree.com” >}}

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

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

</ul>
</figure>

This approach makes content creation easier when you have a large number of links.

Markdown:

{{< references >}}
https://linkone.com
https://linktwo.com
https://linkthree.com
{{< /references >}}

layouts/shortcodes/references.html:

<figure>
  <figcaption>References:</figcaption>
  <ul>
    {{- $url := "" -}}
    {{- range (split .Inner "\n") -}}
      {{- $url = trim . " " -}}
      {{- if gt (len $url) 0 }}
        <li><a href="{{ $url }}">{{ $url }}</a></li>
      {{- end }}
    {{- end }}
  </ul>
</figure>

Absolutely fantastic! It makes it clearer to me now.

Now, how do I range links with their content?

You should create a separate topic for that question, and provide some clarity.

1 Like

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