Link as a function - markdown

Hi, is it possible to add a function to markdown in some way? Also, what would be the best way to make a link with a function, so everytime I change a software version, I change just on a partial for example? Thanks!

Hi, yep, they’re called shortcodes

Thank you. What about having a partial with a link inside it, that I can call as a shortcode? Reading that page couldnt figure how to do it

What did you try so far?

I don’t see any way of doing this that I’ve asked on that page. I’m sorry I’m quite a newbie on this. Could use some help. Thanks.

What I need is the link ref would be a partial so I don’t need to change links in all the pages, I could change just the partial.

You can call a partial from within content files with Inline Shortcodes:

What @alexandros said.

To give you a quick concrete example. Here’s a sample shortcode definition that calls a partial. Let’s say the shortcode is named some-shortcode.html

{{ partial "some-partial.html" . }}

Then use the shortcode in your content like

{{< some-shortcode >}}
1 Like

Still not working. Says failed to extract shortcode. :expressionless:

Show us your code

I have this inside the markdown page:

   {{< testing-shortcode >}}

Then I have a partial name “testing-shortcode.html” inside partials folder. Inside this partial I just have a text to test it out.

And I have in the config file this: enableInlineShortcodes = true

Okay. Now show us your testing-shortcode.html file

<p>Testing Shortcode...</p>

This is what I have inside the testing-shortcode.html - Should be something else?

I’m confused. I thought you were calling a partial from within your shortcode definition? There you just have text hardcoded.

Well, maybe I’m confused as well. I’ll try to explain better what I want to do.

We can use partials to duplicate content thoughout the pages without needing to code everything again, right? So, you could have a banner in partials folder and then just call it like {{ partial “lalala” . }}.

So, now I want to do the same, but only for a link inside a markdown page. And I want the link to be a shortcode or something like that, so I can just change the link in the partial instead of manually change it throughout the whole site.

Does that make sense? I don’t know if I’m explaining myself well. :\

I think I follow you now.
So it sounds like you wouldn’t even need a partial, just a shortcode with a link inside it, something like:

<a href="https://example.com">Link text</a>

Yes, but shortcodes are not working either

What do you mean? Please be more specific.

You should be able to call that shortcode from your content, and it will insert the link.

Ok, found the way to do what I wanted.
It’s here: https://gohugo.io/templates/shortcode-templates/#create-custom-shortcodes

Thank you

Do post your solution once you have it. Am curious.