Crossreferences to index-pages in section not working

I am writing content with crossreferences to other files in other sections, which basically works well with relref or ref.

But I cannot link to the index file in each section.

The content folder holds an _index file on
the top level of each section, the single files are index files beneath folders with the title (pretty URL). _index.md in each section is rendered with the list.html template.

Linking to another single page works, but I cannot link to the section index, which is a list file basically.

I treid several ways to call the section index file, but it seems that it is impossible since it is a list file?

1 Like

I too would like to know how to refer to listing pages with ref and relref. :slight_smile:

I tried to solve this by setting a specific shortcode for relref to override the default one, based off of an example mentioned in How to link to section pages with ref/relref shortcodes?. See the code and location to put it here: https://github.com/vjeantet/hugo-theme-docdock/blob/master/layouts/shortcodes/relref.html. However, this has issues in a number of cases where it doesn’t work and prints the error string into the template:

{{- if in (.Get 0) "/_index.md" -}}
    {{- $path := (strings.TrimSuffix "_index.md" (.Get 0)) -}}
    {{- with .Site.GetPage "section" (trim $path "/") -}}
        {{- .URL -}}
    {{- else -}}
        {{- printf "MUST-DEFINE-TOP-LEVEL-SECTION" -}}
    {{- end -}}
{{- else -}}
    {{- .Get 0 | relref .Page -}}
{{- end -}}