Open navClose nav

Number Field

https://res.cloudinary.com/forestry-demo/image/fetch/c_limit,dpr_auto,f_auto,q_80,w_640/https://forestry.io/uploads/2018/01/number-preview.png

Text input that only accepts numeric values.

Options

  • General
    • Label — the human-friendly label shown above the input field in the editor.
    • Name — the key stored in your content’s front matter, used to access it in your templates.
    • Description — a human friendly description of what the field does and/or instructions for your editors.
    • Hidden — hides the field in the editor, but allows developers to set default values or maintain the field for legacy purposes.
  • Validation
    • Required — prevent changes from being saved if this field is empty.
    • Minimum — the lowest number that may be entered in the field.
    • Maximum — the highest number that may be entered in the field.
    • Step — limits the field to only allow certain increments to be entered into the field.
  • Default — supply a default number.

Templating

You can access this field in your templates using the field’s name:

Hugo

<p>The page's weight is: {{ .Params.weight }}</p> 

Jekyll

<p>The page's weight is: {{ page.weight }}</p> 

Use number fields to sort pages in a loop:

Hugo

{{ range sort .Data.Pages ".Params.weight" "desc" }}
    <h2>{{ .Title }}</h2>
    <p>{{ .Description }}</p>
{{ end }}

Jekyll

{% for post in site.posts | sort:"weight" %}
    <h2>{{ page.title }}</h2>
    <p>{{ page.description }}</p>
{% endif %}

Config Files

You can configure this field in Front Matter Template Config Files as follows:

type: number
name: [String]
label: [String]
description: [String] 
hidden: [true|false]
default: [Number]
config:
  min: [Number]
  max: [Number]
  step: [Number]

Example

type: number
name: weight
label: Weight
description: Set the page's sort order
default: -99
hidden: false
config:
  min: 0
  max: 99
  step: 1

Last updated on December 31, 2017