☁️ Loving our new documentation website? Provide feedback in the CloudCannon Community! ✨

Optional Parser Configuration

Table of contents

Description:

This key toggles whether matching zero times is a valid state for this parser.

Setting this key to true will allow matching zero times as a valid state. If false, this parser requires at least one matching value. Setting this to true is preferred to wrapping the repeating parser inside an optional parser.

By default, this key is false (i.e., at least one matching value is required).

Appears in:
└── Snippet
    └── params
        └── *
            └── Optional Parser Configuration
Type:
Object
Properties:
optionsObject Required#

This key defines configuration options for optional parser configurations.

The value is an object that can contain snippet and remove_empty properties. These options control which snippet configuration is wrapped and whether empty values are removed.

Show examplesHide examples

In this example, we have configured optional parser options with a snippet reference.

Copied to clipboard
_snippets:
  example:
    snippet: <<example [[optional_content]]>>
    params:
      optional_content:
        parser: optional
        options:
          snippet: content
{
  "_snippets": {
    "example": {
      "snippet": "<<example [[optional_content]]>>",
      "params": {
        "optional_content": {
          "parser": "optional",
          "options": {
            "snippet": "content"
          }
        }
      }
    }
  }
}
parser"optional" Required#

This key defines the parser type for optional parser configurations.

The value must be optional. This specifies that the parameter uses the optional parser, which wraps another snippet configuration and makes it optional.

Show examplesHide examples

In this example, we have configured an optional parser for a snippet parameter.

Copied to clipboard
_snippets:
  example:
    snippet: <<example [[optional_content]]>>
    params:
      optional_content:
        parser: optional
        options:
          snippet: content
{
  "_snippets": {
    "example": {
      "snippet": "<<example [[optional_content]]>>",
      "params": {
        "optional_content": {
          "parser": "optional",
          "options": {
            "snippet": "content"
          }
        }
      }
    }
  }
}
Examples:
Open in a new tab