mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-27 06:00:25 +03:00
Merge commit '5be51ac3db
'
This commit is contained in:
commit
653f1c1d46
987 changed files with 12379 additions and 14083 deletions
|
@ -1,48 +1,61 @@
|
|||
---
|
||||
title: Relref
|
||||
title: Relref shortcode
|
||||
linkTitle: Relref
|
||||
description: Insert a relative permalink to the given page reference using the relref shortcode.
|
||||
categories: [shortcodes]
|
||||
categories: []
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: shortcodes
|
||||
weight:
|
||||
weight:
|
||||
---
|
||||
|
||||
{{% note %}}
|
||||
To override Hugo's embedded `relref` shortcode, copy the [source code] to a file with the same name in the `layouts/shortcodes` directory.
|
||||
> [!note]
|
||||
> To override Hugo's embedded `relref` shortcode, copy the [source code] to a file with the same name in the `layouts/shortcodes` directory.
|
||||
|
||||
[source code]: {{% eturl relref %}}
|
||||
{{% /note %}}
|
||||
> [!note]
|
||||
> When working with the Markdown [content format], this shortcode has become largely redundant. Its functionality is now primarily handled by [link render hooks], specifically the embedded one provided by Hugo. This hook effectively addresses all the use cases previously covered by this shortcode.
|
||||
|
||||
{{% note %}}
|
||||
When working with the Markdown [content format], this shortcode has become largely redundant. Its functionality is now primarily handled by [link render hooks], specifically the embedded one provided by Hugo. This hook effectively addresses all the use cases previously covered by this shortcode.
|
||||
## Usage
|
||||
|
||||
[content format]: /content-management/formats/
|
||||
[link render hooks]: /render-hooks/links/
|
||||
{{% /note %}}
|
||||
The `relref` shortcode accepts either a single positional argument (the path) or one or more named arguments, as listed below.
|
||||
|
||||
The `relref` shortcode returns the relative permalink of the given page reference.
|
||||
## Arguments
|
||||
|
||||
Example usage:
|
||||
{{% include "_common/ref-and-relref-options.md" %}}
|
||||
|
||||
```text
|
||||
[Post 1]({{%/* relref "/posts/post-1" */%}})
|
||||
[Post 1]({{%/* relref "/posts/post-1.md" */%}})
|
||||
[Post 1]({{%/* relref "/posts/post-1#foo" */%}})
|
||||
[Post 1]({{%/* relref "/posts/post-1.md#foo" */%}})
|
||||
## Examples
|
||||
|
||||
The `relref` shortcode typically provides the destination for a Markdown link.
|
||||
|
||||
> [!note]
|
||||
> Always use [Markdown notation] notation when calling this shortcode.
|
||||
|
||||
The following examples show the rendered output for a page on the English version of the site:
|
||||
|
||||
```md
|
||||
[Link A]({{%/* ref "/books/book-1" */%}})
|
||||
|
||||
[Link B]({{%/* ref path="/books/book-1" */%}})
|
||||
|
||||
[Link C]({{%/* ref path="/books/book-1" lang="de" */%}})
|
||||
|
||||
[Link D]({{%/* ref path="/books/book-1" lang="de" outputFormat="json" */%}})
|
||||
```
|
||||
|
||||
Rendered:
|
||||
|
||||
```html
|
||||
<a href="/posts/post-1/">Post 1</a>
|
||||
<a href="/posts/post-1/">Post 1</a>
|
||||
<a href="/posts/post-1/#foo">Post 1</a>
|
||||
<a href="/posts/post-1/#foo">Post 1</a>
|
||||
<a href="/en/books/book-1/">Link A</a>
|
||||
|
||||
<a href="/en/books/book-1/">Link B</a>
|
||||
|
||||
<a href="/de/books/book-1/">Link C</a>
|
||||
|
||||
<a href="/de/books/book-1/index.json">Link D</a>
|
||||
```
|
||||
|
||||
{{% note %}}
|
||||
Always use the `{{%/* */%}}` notation when calling this shortcode.
|
||||
{{% /note %}}
|
||||
## Error handling
|
||||
|
||||
{{% include "_common/ref-and-relref-error-handling.md" %}}
|
||||
|
||||
[content format]: /content-management/formats/
|
||||
[link render hooks]: /render-hooks/links/
|
||||
[Markdown notation]: /content-management/shortcodes/#notation
|
||||
[source code]: {{% eturl relref %}}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue