Open navClose nav

Toggle 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/toggle-preview.png

A boolean toggle.

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.
  • Default — set the default toggle state.

Templating

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

Hugo

{{ if .Params.is_featured }}
    // Do something special!
{{ end }}

Jekyll

{{ if page.is_featured }}
    // Do something special!
{{ end }}

VuePress

<div v-if="$page.frontmatter.is_featured">
    // Do something special!
</div>

Use a toggle to filter pages in a loop:

Hugo

{{ range where .Data.Pages ".Params.is_featured" true }}
    <h2>{{ .Title }}</h2>
    <p>{{ .Description }}</p>
{{ end }}

Jekyll

{% for post in site.posts | where:"is_featured", "true" %}
    <h2>{{ page.title }}</h2>
    <p>{{ page.description }}</p>
{% endif %}

VuePress

<template>
  <div class="featured-posts">
    <div v-for="post in featuredPosts" class="featured-post">
      <h2>{{ post.frontmatter.title }}</h2>
      <p>{{ post.frontmatter.description }}</p>
    </div>
  </div>
</template>
<script>
   export default {
    computed: {
      featuredPosts() {
        return this.$site.pages
          .filter(page => page.path.startsWith("/posts/")
          .filter(page => page.frontmatter.is_featured)
      }
    }
  }
</script>

Config Files

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

type: boolean
name: [String]
label: [String]
description: [String]
default: [true|false]
hidden: [true|false]

Example

type: boolean
name: is_featured
label: Is Featured?
description: Mark this page as featured
default: true
hidden: false

Last updated on December 31, 2017