Can I use relref when I have multiple pages with the same title?

TLDR: If I have multiple pages with the same title, how can I give a page a unique identifier that relref can use?


Here’s my scenario:

content/
    install/
        windows.md
        mac.md
        linux.md
    troubleshooting/
        windows.md
        mac.md
        linux.md
    index.md

Say I want to use relref inside index.md:

Find out how to [install this application on Linux]({{< relref "linux" >}}).

This fails, because Hugo can find two pages with the title linux. I could add the folder name to the relref, so something like {{< relref "install/linux" >}}. This works. But if I want to change the directory structure in the future, then I’ll have to update all these links again… For example, if I changed the structure to:

content/
    install/
        cli/
            windows.md
            mac.md
            linux.md
        desktop/
            windows.md
            mac.md
            linux.md
    troubleshooting/
        windows.md
        mac.md
        linux.md
    index.md

Then I’d have to go into index.md and change the relref link to {{< relref "install/cli/linux" >}}. Obviously this is a simplifed example; in a production site I’d have to update lots of links.

How can I assign problem pages a unique identifier that relref can then use to create a link to each page? Or may I shouldn’t be using relref at all?

The path is the unique identifier. You can not configure an alternate identifier for the ref/relref functions or shortcodes, nor can you configure an alternate identifier for the .GetPage method.

If you really wanted to do this, you could create your own shortcode that uses a where clause against the entire site’s page collection, looking for a specific parameter in front matter.

1 Like

Ah ok. That’s unfortunate, but understandable. I was hoping I could do some magic with the identifier page variable, but that’s just for menus as far as I understand. Thanks for the prompt answer!

1 Like

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