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

remove_empty

Table of contents

Description:

This key toggles whether this key-value pair should be omitted altogether if the value is empty.

Setting this key to true will omit the key-value pair if the value is empty. Requires that this key is also set as optional, as otherwise the snippet would not re-parse.

By default, this key is false (i.e., empty key-value pairs are not omitted).

Appears in:
└── Snippet Model
    └── remove_empty
Type:
boolean
Default value:
false
Examples:
Copied to clipboard
parser: key_values
options:
  models:
    - editor_key: href
    - editor_key: target
    - editor_key: class
      optional: true
      remove_empty: true
{
  "parser": "key_values",
  "options": {
    "models": [
      {
        "editor_key": "href"
      },
      {
        "editor_key": "target"
      },
      {
        "editor_key": "class",
        "optional": true,
        "remove_empty": true
      }
    ]
  }
}

Example usage:

Markdown
Copied to clipboard
## My blog post

<a href="#link" target="_blank" class=""> ... </a> 
<a href="#link" target="_blank"> ... </a>  

Morbi leo risus, porta ac consectetur ac, vestibulum at eros.
With `remove_empty: true` both of these anchor tags will be output as `<a href="#link" target="_blank"> ... </a>` as the `class` key contains no value.
If `remove_empty: false` was set, this snippet would be output as `<a href="#link" target="_blank" class=""> ... </a>`. The empty `class` key would be written even if it did not originally appear in the parsed source.
Open in a new tab