8390a4a3aAdd Void Linux installation instructionsd6099aae8Update link to PostCSS plugins25dad4693netlify: Hugo 0.139.42b1fa118cFix typo3ef1eb505Update hosting-on-aws-amplifyc0f6d35d6Fix typoaa54d4301Correct directory name98aa26bdbImprove instructions for hosting with AWS Amplifya07638a80Add new-in badges6ad018055netlify: Hugo 0.139.31050835d6Update title of hugo.Store pageebbd2e851Clarify the shortcode Ordinal methodb7716ed95Revise code block render hook for Mermaid diagramsf1da9b6eanetlify: Hugo 0.139.2d8ac9f428Downgrade the Go toolchain in go.mod to a slightly older Go version254b3c4f2netlify: Hugo 0.139.103e666038Add hugo.Store, site.Store and Shortcode.Store157e8983bUpdate Anchorize.md59fa9f214Document the PageRef menu entry methodbda544ccedocs(transform.Unmarshal): match lang attribute to title language in examples1985886bdAdjust front matter of shared Markdown snippetsda5bd70d1Fix typo431b65d6bUpdate themeb63ef69f5Update style guidanced50ed3422Remove old new-in badges12bfb9933Update docs.yaml0b936cacdnetlify: Hugo 0.139.0ab7668b4ddartsass: Add silenceDeprecations option154df9bfcMerge commit '838bd312b1a287bb33962ad478dbc54737654f35'efa80477cdocs: Regen CLI docsad99e4a7adocs: Regenerate CLI docs git-subtree-dir: docs git-subtree-split:8390a4a3ac
2.9 KiB
title, description, categories, keywords, action, toc
| title | description | categories | keywords | action | toc | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| PageRef | Returns the `pageRef` property of the given menu entry. |
|
true |
The use case for this method is rare.
In almost also scenarios you should use the URL method instead.
Explanation
If you specify a pageRef property when defining a menu entry in your site configuration, Hugo looks for a matching page when rendering the entry.
If a matching page is found:
- The
URLmethod returns the page's relative permalink - The
Pagemethod returns the correspondingPageobject - The
HasMenuCurrentandIsMenuCurrentmethods on aPageobject return the expected values
If a matching page is not found:
- The
URLmethod returns the entry'surlproperty if set, else an empty string - The
Pagemethod returns nil - The
HasMenuCurrentandIsMenuCurrentmethods on aPageobject returnfalse
{{% note %}}
In almost also scenarios you should use the URL method instead.
{{% /note %}}
Example
This example is contrived.
{{% note %}}
In almost also scenarios you should use the URL method instead.
{{% /note %}}
Consider this content structure:
content/
├── products.md
└── _index.md
And this menu definition:
{{< code-toggle file=hugo >}} menus.main name = 'Products' pageRef = '/products' weight = 10 menus.main name = 'Services' pageRef = '/services' weight = 20 {{< /code-toggle >}}
With this template code:
{{< code file=layouts/partials/menu.html >}}
-
{{ range .Site.Menus.main }}
- {{ .Name }} {{ end }}
Hugo render this HTML:
<ul>
<li><a href="/products/">Products</a></li>
<li><a href="">Services</a></li>
</ul>
In the above note that the href attribute of the second anchor element is blank because Hugo was unable to find the "services" page.
With this template code:
{{< code file=layouts/partials/menu.html >}}
-
{{ range .Site.Menus.main }}
- {{ .Name }} {{ end }}
Hugo renders this HTML:
<ul>
<li><a href="/products/">Products</a></li>
<li><a href="/services">Services</a></li>
</ul>
In the above note that Hugo populates the href attribute of the second anchor element with the pageRef property as defined in the site configuration because the template code falls back to the PageRef method.