Defining more ways to add new files

Create or change actions for the add dropdown menu in the collection list with _add_options.

_add_options are an array of objects that extend the functionality of the Add button in a collection. They are added to your CloudCannon collection configuration. Learn more about defining collections in CloudCannon.

Note

Add options can include actions on the current collection, other collections, and external links.

Examples

Some example configurations are shown below:

These options are set in _config.yml on the cloudcannon.collections level. For example:

_config.yml
cloudcannon:
  collections:
    posts:
      _add_options:
        - name: Add Post
          href: "cloudcannon::editor/:collections_dir/:base_path/.:extension🆕"
        - name: Add Draft
          href: "cloudcannon::editor/:collections_dir/:base_path_draftify/.:extension🆕:base_path_postify/_defaults.:extension"

Extended example:

_config.yml
cloudcannon:
  collections:
    staff:
      _add_options:
        - name: Add Staff Member
          href: "cloudcannon:explore/_staff/.md🆕"
        - name: Add Author
          icon: edit
          href: "cloudcannon:explore/_staff/.md🆕/_staff/_defaults-author.md"
    offices:
      _add_options:
        - name: Add Office
          href: "cloudcannon:explore/_offices/.md🆕"
        - name: Add Office Location
          icon: public
          href: "cloudcannon:explore/_data/office-locations.yml"
        - name: Search on Google
          icon: search
          href: "https://www.google.com/"

For the offices collection, this will result in the following menu:

Screenshot of a collection with add options configured

Options

_add_options are configured using the following keys:

name - String

The text displayed for the menu item.

icon - String

The icon next to the text in the menu item. Must match a Material Icon name.

href - String

The link that opens when the option is clicked.

The href field is can be an external link, but it can also be formatted as an Editor Link. Editor Links must begin with cloudcannon:. There are a number of variables you can use to make these links more flexible:

:editor

Usually explore, is update if creating an HTML file.

:collections_dir

The collections path from the build information.

:base_path

The path the editor is currently navigated to, not including the source or :collections_dir.

:base_path_postify

Same as :base_path, with /_drafts/ changed to /_posts/.

:base_path_draftify

Same as :base_path, with /_posts/ changed to /_drafts/.

:source

The source path defined your site config.

:extension

The extension of the default content file, not prefixed with ..

🆕

Signifies that a new file will be created. To specify a file to use as a template, declare the path to the file after the 🆕 emoji. This path may also use the parameters specified above.

You can also explicitly declare these variables (e.g. use explore instead of :editor).

Note

If no default content file is specified after 🆕, CloudCannon will use the Collection Defaults file. If no defaults file exists, CloudCannon will use an existing file in the collection as a template.

Was this article helpful? or Suggest an improvement >

Related articles

Other Resources

  1. Material Icons