mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-29 06:12:02 -05:00
parent
a50356b9a2
commit
036e260d8d
1 changed files with 29 additions and 1 deletions
|
@ -73,6 +73,9 @@ The following logical operators are available with `where`:
|
||||||
`intersect`
|
`intersect`
|
||||||
: `true` if a given field value that is a slice/array of strings or integers contains elements in common with the matching value; it follows the same rules as the [`intersect` function][intersect].
|
: `true` if a given field value that is a slice/array of strings or integers contains elements in common with the matching value; it follows the same rules as the [`intersect` function][intersect].
|
||||||
|
|
||||||
|
`like`
|
||||||
|
: `true` if a given field value matches a regular expression. Use the `like` operator to compare `string` values. Returns `false` when comparing other data types to the regular expression.
|
||||||
|
|
||||||
## Use `where` with boolean values
|
## Use `where` with boolean values
|
||||||
When using booleans you should not put quotation marks.
|
When using booleans you should not put quotation marks.
|
||||||
```go-html-template
|
```go-html-template
|
||||||
|
@ -81,7 +84,6 @@ When using booleans you should not put quotation marks.
|
||||||
{{ end }}
|
{{ end }}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## Use `where` with `intersect`
|
## Use `where` with `intersect`
|
||||||
|
|
||||||
```go-html-template
|
```go-html-template
|
||||||
|
@ -102,6 +104,32 @@ You can also put the returned value of the `where` clauses into a variable:
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{< /code >}}
|
{{< /code >}}
|
||||||
|
|
||||||
|
## Use `where` with `like`
|
||||||
|
|
||||||
|
This example matches pages where the "foo" parameter begins with "ab":
|
||||||
|
|
||||||
|
```go-html-template
|
||||||
|
{{ range where site.RegularPages "Params.foo" "like" "^ab" }}
|
||||||
|
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
|
||||||
|
{{ end }}
|
||||||
|
```
|
||||||
|
|
||||||
|
When specifying the regular expression, use a raw [string literal] (backticks) instead of an interpreted string literal (double quotes) to simplify the syntax. With an interpreted string literal you must escape backslashes.
|
||||||
|
|
||||||
|
[string literal]: https://go.dev/ref/spec#String_literals
|
||||||
|
|
||||||
|
This function uses the [RE2] regular expression library. See the [RE2 syntax documentation] for details. Note that the RE2 `\C` escape sequence is not supported.
|
||||||
|
|
||||||
|
[RE2]: https://github.com/google/re2/
|
||||||
|
[RE2 syntax documentation]: https://github.com/google/re2/wiki/Syntax/
|
||||||
|
|
||||||
|
{{% note %}}
|
||||||
|
The RE2 syntax is a subset of that accepted by [PCRE], roughly speaking, and with various [caveats].
|
||||||
|
|
||||||
|
[caveats]: https://swtch.com/~rsc/regexp/regexp3.html#caveats
|
||||||
|
[PCRE]: https://www.pcre.org/
|
||||||
|
{{% /note %}}
|
||||||
|
|
||||||
## Use `where` with `first`
|
## Use `where` with `first`
|
||||||
|
|
||||||
Using `first` and `where` together can be very
|
Using `first` and `where` together can be very
|
||||||
|
|
Loading…
Reference in a new issue