This commit is contained in:
Bjørn Erik Pedersen 2018-07-18 11:05:58 +02:00
commit 59ebc83d72
No known key found for this signature in database
GPG key ID: 330E6E2BD4859D8F
106 changed files with 307 additions and 279 deletions

View file

@ -39,7 +39,7 @@ You can use `after` in combination with the [`first` function][] and Hugo's [pow
{{ define "main" }}
<section class="row featured-article">
<h2>Featured Article</h2>
{{ range first 1 .Data.Pages.ByPublishDate.Reverse }}
{{ range first 1 .Pages.ByPublishDate.Reverse }}
<header>
<h3><a href="{{.Permalink}}">{{.Title}}</a></h3>
</header>
@ -48,7 +48,7 @@ You can use `after` in combination with the [`first` function][] and Hugo's [pow
</section>
<div class="row recent-articles">
<h2>Recent Articles</h2>
{{ range first 3 (after 1 .Data.Pages.ByPublishDate.Reverse) }}
{{ range first 3 (after 1 .Pages.ByPublishDate.Reverse) }}
<section class="recent-article">
<header>
<h3><a href="{{.Permalink}}">{{.Title}}</a></h3>

View file

@ -21,8 +21,7 @@ aliases: []
```
{{ range first 10 .Data.Pages }}
{{ range first 10 .Pages }}
{{ .Render "summary" }}
{{ end }}
```

View file

@ -10,14 +10,18 @@ menu:
docs:
parent: "functions"
keywords: [menus]
signature: ["HasMenuCurrent"]
signature: ["PAGE.HasMenuCurrent MENU MENUENTRY"]
workson: [menus]
hugoversion:
relatedfuncs: []
relatedfuncs: ["IsMenuCurrent"]
deprecated: false
toc: false
draft: true
draft: false
aliases: []
---
Used in [menu templates](/templates/menu-templates/).
`.HasMenuCurrent` is a method in `Page` object returning a _boolean_ value. It
returns `true` if the PAGE is the same object as the `.Page` in one of the
**children menu entries** under MENUENTRY in a given MENU.
You can find its example use in [menu templates](/templates/menu-templates/).

View file

@ -10,14 +10,18 @@ menu:
docs:
parent: "functions"
keywords: [menus]
signature: ["IsMenuCurrent"]
signature: ["PAGE.IsMenuCurrent MENU MENUENTRY"]
workson: [menus]
hugoversion:
relatedfuncs: []
relatedfuncs: ["HasMenuCurrent"]
deprecated: false
draft: true
draft: false
aliases: []
needsexample: true
---
Used in [menu templates](/templates/menu-templates/).
`.IsMenuCurrent` is a method in `Page` object returning a _boolean_ value. It
returns `true` if the PAGE is the same object as the `.Page` in MENUENTRY in a
given MENU.
You can find its example use in [menu templates](/templates/menu-templates/).

View file

@ -23,8 +23,7 @@ aliases: []
```
{{ range last 10 .Data.Pages }}
{{ range last 10 .Pages }}
{{ .Render "summary" }}
{{ end }}
```

View file

@ -26,7 +26,7 @@ This function is only available when applied to a single piece of content within
This example could render a piece of content using the content view located at `/layouts/_default/summary.html`:
```
{{ range .Data.Pages }}
{{ range .Pages }}
{{ .Render "summary"}}
{{ end }}
```

View file

@ -33,11 +33,19 @@ See [this Go issue](https://github.com/golang/go/issues/10608) for the main moti
For a detailed analysis of `.Scratch` and in context use cases, see this [post](https://regisphilibert.com/blog/2017/04/hugo-scratch-explained-variable/).
{{% /note %}}
## Methods
## Get a Scratch
`Scratch` is added to both `Page` and `Shortcode` -- with following methods:
From Hugo `0.43` you can also create a locally scoped `Scratch` by calling `newScratch`:
```go-html-template
$scratch := newScratch
$scratch.Set "greeting" "Hello"
```
A `Scratch` is also added to both `Page` and `Shortcode`. `Sratch` have the following methods:
#### .Set
Set the given value to a given key
```go-html-template

View file

@ -23,7 +23,7 @@ needsexample: true
`where` filters an array to only the elements containing a matching value for a given field.
```go-html-template
{{ range where .Data.Pages "Section" "post" }}
{{ range where .Pages "Section" "post" }}
{{ .Content }}
{{ end }}
```
@ -45,7 +45,7 @@ series: golang
It can also be used with the logical operators `!=`, `>=`, `in`, etc. Without an operator, `where` compares a given field with a matching value equivalent to `=`.
```go-html-template
{{ range where .Data.Pages "Section" "!=" "post" }}
{{ range where .Pages "Section" "!=" "post" }}
{{ .Content }}
{{ end }}
```
@ -104,7 +104,7 @@ You can also put the returned value of the `where` clauses into a variable:
The following grabs the first five content files in `post` using the [default ordering](/templates/lists/) for lists (i.e., `weight => date`):
{{< code file="where-with-first.html" >}}
{{ range first 5 (where .Data.Pages "Section" "post") }}
{{ range first 5 (where .Pages "Section" "post") }}
{{ .Content }}
{{ end }}
{{< /code >}}
@ -114,7 +114,7 @@ The following grabs the first five content files in `post` using the [default or
You can also nest `where` clauses to drill down on lists of content by more than one parameter. The following first grabs all pages in the "blog" section and then ranges through the result of the first `where` clause and finds all pages that are *not* featured:
```go-html-template
{{ range where (where .Data.Pages "Section" "blog" ) ".Params.featured" "!=" "true" }}
{{ range where (where .Pages "Section" "blog" ) ".Params.featured" "!=" "true" }}
```
## Unset Fields
@ -129,7 +129,7 @@ Only the following operators are available for `nil`
* `!=`, `<>`, `ne`: True if the given field is set.
```go-html-template
{{ range where .Data.Pages ".Params.specialpost" "!=" nil }}
{{ range where .Pages ".Params.specialpost" "!=" nil }}
{{ .Content }}
{{ end }}
```