| 1 |
--- |
| 2 |
title: Get |
| 3 |
description: Returns a slice of weighted pages to which the given term has been assigned. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
returnType: page.WeightedPages |
| 9 |
signatures: [TAXONOMY.Get TERM] |
| 10 |
--- |
| 11 |
|
| 12 |
The `Get` method on a `Taxonomy` object returns a slice of [weighted pages](g) to which the given [term](g) has been assigned. |
| 13 |
|
| 14 |
{{% include "/_common/methods/taxonomy/get-a-taxonomy-object.md" %}} |
| 15 |
|
| 16 |
## Get the weighted pages |
| 17 |
|
| 18 |
Now that we have captured the `genres` `Taxonomy` object, let's get the weighted pages to which the `suspense` term has been assigned: |
| 19 |
|
| 20 |
```go-html-template |
| 21 |
{{ $weightedPages := $taxonomyObject.Get "suspense" }} |
| 22 |
``` |
| 23 |
|
| 24 |
The above is equivalent to: |
| 25 |
|
| 26 |
```go-html-template |
| 27 |
{{ $weightedPages := $taxonomyObject.suspense }} |
| 28 |
``` |
| 29 |
|
| 30 |
If the term is not a valid [identifier](g), you cannot use the [chaining](g) syntax. For example, this will throw an error because the identifier contains a hyphen: |
| 31 |
|
| 32 |
```go-html-template |
| 33 |
{{ $weightedPages := $taxonomyObject.my-genre }} |
| 34 |
``` |
| 35 |
|
| 36 |
You could also use the [`index`][] function, but the syntax is more verbose: |
| 37 |
|
| 38 |
```go-html-template |
| 39 |
{{ $weightedPages := index $taxonomyObject "my-genre" }} |
| 40 |
``` |
| 41 |
|
| 42 |
To inspect the data structure: |
| 43 |
|
| 44 |
```go-html-template |
| 45 |
<pre>{{ debug.Dump $weightedPages }}</pre> |
| 46 |
``` |
| 47 |
|
| 48 |
## Example |
| 49 |
|
| 50 |
With this template: |
| 51 |
|
| 52 |
```go-html-template |
| 53 |
{{ $weightedPages := $taxonomyObject.Get "suspense" }} |
| 54 |
{{ range $weightedPages }} |
| 55 |
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2> |
| 56 |
{{ end }} |
| 57 |
``` |
| 58 |
|
| 59 |
Hugo renders: |
| 60 |
|
| 61 |
```html |
| 62 |
<h2><a href="/books/jamaica-inn/">Jamaica inn</a></h2> |
| 63 |
<h2><a href="/books/death-on-the-nile/">Death on the nile</a></h2> |
| 64 |
<h2><a href="/books/and-then-there-were-none/">And then there were none</a></h2> |
| 65 |
``` |
| 66 |
|
| 67 |
[`index`]: /functions/collections/indexfunction/ |