2022-09-30 11:39:35 -04:00
---
2022-11-04 17:41:12 -04:00
group: Intro
title: Beta Features
2022-10-25 09:18:18 -04:00
weight: 200
2022-09-30 11:39:35 -04:00
---
2022-11-04 17:41:12 -04:00
Static CMS runs new functionality in an open beta format from time to time. That means that this functionality is totally available for use, an it might be ready for primetime, but it could break or change without notice.
2022-09-30 11:39:35 -04:00
2022-11-04 17:41:12 -04:00
**Use these features at your own risk.**
2022-09-30 11:39:35 -04:00
## i18n Support
The CMS can provide a side by side interface for authoring content in multiple languages.
Configuring the CMS for i18n support requires top level configuration, collection level configuration and field level configuration.
### Top level configuration
2022-11-07 10:27:58 -05:00
<CodeTabs>
2022-09-30 11:39:35 -04:00
```yaml
i18n:
# Required and can be one of multiple_folders, multiple_files or single_file
# multiple_folders - persists files in `<folder>/<locale>/<slug>.<extension>`
# multiple_files - persists files in `<folder>/<slug>.<locale>.<extension>`
# single_file - persists a single file in `<folder>/<slug>.<extension>`
structure: multiple_folders
2022-11-07 10:27:58 -05:00
# Required - a list of locales to show in the editor UI
locales: [en, de, fr]
# Optional, defaults to the first item in locales.
# The locale to be used for fields validation and as a baseline for the entry.
defaultLocale: en
```
2022-09-30 11:39:35 -04:00
2022-11-07 10:27:58 -05:00
```js
i18n: {
/**
* Required and can be one of multiple_folders, multiple_files or single_file
* multiple_folders - persists files in `<folder>/<locale>/<slug>.<extension>`
* multiple_files - persists files in `<folder>/<slug>.<locale>.<extension>`
* single_file - persists a single file in `<folder>/<slug>.<extension>`
*/
structure: 'multiple_folders',
// Required - a list of locales to show in the editor UI
locales: ['en', 'de', 'fr'],
/**
* Optional, defaults to the first item in locales.
* The locale to be used for fields validation and as a baseline for the entry.
*/
defaultLocale: 'en'
},
2022-09-30 11:39:35 -04:00
```
2022-11-07 10:27:58 -05:00
</CodeTabs>
2022-09-30 11:39:35 -04:00
### Collection level configuration
2022-11-07 10:27:58 -05:00
<CodeTabs>
2022-09-30 11:39:35 -04:00
```yaml
collections:
2022-11-04 17:41:12 -04:00
- name: i18n_content
2022-09-30 11:39:35 -04:00
# same as the top level, but all fields are optional and defaults to the top level
# can also be a boolean to accept the top level defaults
i18n: true
```
2022-11-07 10:27:58 -05:00
```js
collections: [
{
name: 'i18n_content',
/**
* same as the top level, but all fields are optional and defaults to the top level
* can also be a boolean to accept the top level defaults
*/
i18n: true
},
],
```
</CodeTabs>
2022-09-30 11:39:35 -04:00
When using a file collection, you must also enable i18n for each individual file:
2022-11-07 10:27:58 -05:00
<CodeTabs>
2022-09-30 11:39:35 -04:00
```yaml
collections:
2022-11-04 17:41:12 -04:00
- name: pages
2022-09-30 11:39:35 -04:00
label: Pages
# Configure i18n for this collection.
i18n:
structure: single_file
locales: [en, de, fr]
files:
2022-11-04 17:41:12 -04:00
- name: about
2022-09-30 11:39:35 -04:00
label: About Page
file: site/content/about.yml
# Enable i18n for this file.
i18n: true
fields:
2022-11-04 17:41:12 -04:00
- { label: Title, name: title, widget: string, i18n: true }
2022-09-30 11:39:35 -04:00
```
2022-11-07 10:27:58 -05:00
```js
collections: [
{
name: 'pages',
label: 'Pages',
// Configure i18n for this collection.
i18n: {
structure: 'single_file',
locales: ['en', 'de', 'fr']
},
files: [
{
name: 'about',
label: 'About Page',
file: 'site/content/about.yml',
// Enable i18n for this file.
i18n: true,
fields: [
{ label: 'Title', name: 'title', widget: 'string', i18n: true }
],
},
],
},
],
```
</CodeTabs>
2022-09-30 11:39:35 -04:00
### Field level configuration
2022-11-07 10:27:58 -05:00
<CodeTabs>
2022-09-30 11:39:35 -04:00
```yaml
fields:
- label: Title
2022-11-04 17:41:12 -04:00
name: title
2022-09-30 11:39:35 -04:00
widget: string
# same as 'i18n: translate'. Allows translation of the title field
i18n: true
- label: Date
2022-11-04 17:41:12 -04:00
name: date
2022-09-30 11:39:35 -04:00
widget: datetime
# The date field will be duplicated from the default locale.
i18n: duplicate
- label: Body
2022-11-04 17:41:12 -04:00
name: body
2022-09-30 11:39:35 -04:00
# The markdown field will be omitted from the translation.
widget: markdown
```
2022-11-07 10:27:58 -05:00
```js
fields: [
{
label: 'Title',
name: 'title',
widget: 'string',
// same as 'i18n: translate'. Allows translation of the title field
i18n: true
},
{
label: 'Date',
name: 'date',
widget: 'datetime',
// The date field will be duplicated from the default locale.
i18n: 'duplicate'
},
{
label: 'Body',
name: 'body',
// The markdown field will be omitted from the translation.
widget: 'markdown'
},
],
```
</CodeTabs>
2022-09-30 11:39:35 -04:00
Example configuration:
2022-11-07 10:27:58 -05:00
<CodeTabs>
2022-09-30 11:39:35 -04:00
```yaml
i18n:
structure: multiple_folders
locales: [en, de, fr]
collections:
2022-11-04 17:41:12 -04:00
- name: posts
2022-09-30 11:39:35 -04:00
label: Posts
folder: content/posts
create: true
i18n: true
fields:
- label: Title
2022-11-04 17:41:12 -04:00
name: title
2022-09-30 11:39:35 -04:00
widget: string
i18n: true
- label: Date
2022-11-04 17:41:12 -04:00
name: date
2022-09-30 11:39:35 -04:00
widget: datetime
i18n: duplicate
- label: Body
2022-11-04 17:41:12 -04:00
name: body
2022-09-30 11:39:35 -04:00
widget: markdown
```
2022-11-07 10:27:58 -05:00
```js
i18n: {
structure: 'multiple_folders',
locales: ['en', 'de', 'fr']
},
collections: [
{
name: 'posts',
label: 'Posts',
folder: 'content/posts',
create: true,
i18n: true,
fields: [
{ label: 'Title', name: 'title', widget: 'string', i18n: true },
{ label: 'Date', name: 'date', widget: 'datetime', i18n: 'duplicate' },
{ label: 'Body', name: 'body', widget: 'markdown' },
],
},
],
```
</CodeTabs>
2022-09-30 11:39:35 -04:00
### Limitations
1. File collections support only `structure: single_file`.
2. List widgets only support `i18n: true`. `i18n` configuration on sub fields is ignored.
3. Object widgets only support `i18n: true` and `i18n` configuration should be done per field:
2022-11-07 10:27:58 -05:00
<CodeTabs>
2022-09-30 11:39:35 -04:00
```yaml
- label: 'Object'
2022-11-04 17:41:12 -04:00
name: 'object'
2022-09-30 11:39:35 -04:00
widget: 'object'
i18n: true
fields:
2022-11-04 17:41:12 -04:00
- { label: 'String', name: 'string', widget: 'string', i18n: true }
- { label: 'Date', name: 'date', widget: 'datetime', i18n: duplicate }
- { label: 'Boolean', name: 'boolean', widget: 'boolean', i18n: duplicate }
2022-09-30 11:39:35 -04:00
- {
label: 'Object',
2022-11-04 17:41:12 -04:00
name: 'object',
2022-09-30 11:39:35 -04:00
widget: 'object',
i18n: true,
2022-11-04 17:41:12 -04:00
field: { label: 'String', name: 'string', widget: 'string', i18n: duplicate },
2022-09-30 11:39:35 -04:00
}
```
2022-11-07 10:27:58 -05:00
```js
{
label: 'Object',
name: 'object',
widget: 'object',
i18n: true,
fields: [
{ label: 'String', name: 'string', widget: 'string', i18n: true },
{ label: 'Date', name: 'date', widget: 'datetime', i18n: 'duplicate' },
{ label: 'Boolean', name: 'boolean', widget: 'boolean', i18n: 'duplicate' },
{
label: 'Object',
name: 'object',
widget: 'object',
i18n: true,
field: { label: 'String', name: 'string', widget: 'string', i18n: 'duplicate' },
},
],
},
```
</CodeTabs>
2022-09-30 11:39:35 -04:00
## Folder Collections Path
2022-11-04 17:41:12 -04:00
See [Folder Collections Path](/docs/collection-types#folder-collections-path).
2022-09-30 11:39:35 -04:00
2022-11-04 17:41:12 -04:00
## Nested Collections
2022-09-30 11:39:35 -04:00
2022-11-04 17:41:12 -04:00
Seed [Nested Collections](/docs/collection-types#nested-collections).
2022-09-30 11:39:35 -04:00
## Custom Mount Element
2022-10-02 20:06:20 -04:00
Static CMS always creates its own DOM element for mounting the application, which means it always takes over the entire page, and is generally inflexible if you're trying to do something creative, like injecting it into a shared context.
2022-09-30 11:39:35 -04:00
2022-10-02 20:06:20 -04:00
You can now provide your own element for Static CMS to mount in by setting the target element's ID as `nc-root`. If Static CMS finds an element with this ID during initialization, it will mount within that element instead of creating its own.
2022-09-30 11:39:35 -04:00
## Commit Message Templates
2022-11-07 10:27:58 -05:00
You can customize the templates used by Static CMS to generate commit messages by setting the `commit_messages` option under `backend` in your Static CMS `config`.
2022-09-30 11:39:35 -04:00
Template tags wrapped in curly braces will be expanded to include information about the file changed by the commit. For example, `{{path}}` will include the full path to the file changed.
2022-11-07 10:27:58 -05:00
Setting up your Static CMS `config` to recreate the default values would look like this:
2022-09-30 11:39:35 -04:00
2022-11-07 10:27:58 -05:00
<CodeTabs>
2022-09-30 11:39:35 -04:00
```yaml
backend:
commit_messages:
2022-11-07 10:27:58 -05:00
create: Create {{collection}} "{{slug}}"
update: Update {{collection}} "{{slug}}"
delete: Delete {{collection}} "{{slug}}"
uploadMedia: Upload "{{path}}"
deleteMedia: Delete "{{path}}"
```
```js
backend: {
commit_messages: {
create: 'Create {{collection}} "{{slug}}"',
update: 'Update {{collection}} "{{slug}}"',
delete: 'Delete {{collection}} "{{slug}}"',
uploadMedia: 'Upload "{{path}}"',
deleteMedia: 'Delete "{{path}}"',
},
},
2022-09-30 11:39:35 -04:00
```
2022-11-07 10:27:58 -05:00
</CodeTabs>
2022-10-02 20:06:20 -04:00
Static CMS generates the following commit types:
2022-09-30 11:39:35 -04:00
2022-11-04 17:41:12 -04:00
| Commit type | When is it triggered? | Available template tags |
| ------------- | ---------------------------- | ----------------------------------------------------------- |
| `create` | A new entry is created | `slug`, `path`, `collection`, `author-login`, `author-name` |
| `update` | An existing entry is changed | `slug`, `path`, `collection`, `author-login`, `author-name` |
| `delete` | An existing entry is deleted | `slug`, `path`, `collection`, `author-login`, `author-name` |
| `uploadMedia` | A media file is uploaded | `path`, `author-login`, `author-name` |
| `deleteMedia` | A media file is deleted | `path`, `author-login`, `author-name` |
2022-09-30 11:39:35 -04:00
Template tags produce the following output:
2022-11-04 17:41:12 -04:00
- `{{slug}}`: the url-safe filename of the entry changed
- `{{collection}}`: the name of the collection containing the entry changed
- `{{path}}`: the full path to the file changed
- `{{message}}`: the relevant message based on the current change (e.g. the `create` message when an entry is created)
- `{{author-login}}`: the login/username of the author
- `{{author-name}}`: the full name of the author (might be empty based on the user's profile)
2022-09-30 11:39:35 -04:00
## Image widget file size limit
You can set a limit to as what the maximum file size of a file is that users can upload directly into a image field.
Example config:
2022-11-07 10:27:58 -05:00
<CodeTabs>
2022-09-30 11:39:35 -04:00
```yaml
- label: 'Featured Image'
2022-11-04 17:41:12 -04:00
name: 'thumbnail'
2022-09-30 11:39:35 -04:00
widget: 'image'
default: '/uploads/chocolate-dogecoin.jpg'
media_library:
config:
max_file_size: 512000 # in bytes, only for default media library
```
2022-11-07 10:27:58 -05:00
```js
{
label: 'Featured Image',
name: 'thumbnail',
widget: 'image',
default: '/uploads/chocolate-dogecoin.jpg',
media_library: {
config: {
max_file_size: 512000 // in bytes, only for default media library
},
},
},
```
</CodeTabs>
2022-09-30 11:39:35 -04:00
## Summary string template transformations
You can apply transformations on fields in a summary string template using filter notation syntax.
Example config:
2022-11-07 10:27:58 -05:00
<CodeTabs>
2022-09-30 11:39:35 -04:00
```yaml
collections:
2022-11-04 17:41:12 -04:00
- name: 'posts'
2022-09-30 11:39:35 -04:00
label: 'Posts'
folder: '_posts'
2022-11-07 10:27:58 -05:00
summary: "{{title | upper}} - {{date | date('YYYY-MM-DD')}} - {{body | truncate(20, '***')}}"
2022-09-30 11:39:35 -04:00
fields:
2022-11-04 17:41:12 -04:00
- { label: 'Title', name: 'title', widget: 'string' }
- { label: 'Publish Date', name: 'date', widget: 'datetime' }
- { label: 'Body', name: 'body', widget: 'markdown' }
2022-09-30 11:39:35 -04:00
```
2022-11-07 10:27:58 -05:00
```js
collections: [
{
name: 'posts',
label: 'Posts',
folder: '_posts',
summary: "{{title | upper}} - {{date | date('YYYY-MM-DD')}} - {{body | truncate(20, '***')}}",
fields: [
{ label: 'Title', name: 'title', widget: 'string' },
{ label: 'Publish Date', name: 'date', widget: 'datetime' },
{ label: 'Body', name: 'body', widget: 'markdown' },
],
},
],
```
</CodeTabs>
2022-09-30 11:39:35 -04:00
The above config will transform the title field to uppercase and format the date field using `YYYY-MM-DD` format.
2022-11-04 17:41:12 -04:00
Available transformations are `upper`, `lower`, `date('<format>')`, `default('defaultValue')`, `ternary('valueForTrue','valueForFalse')` and `truncate(<number>)`/`truncate(<number>, '<string>')`
2022-09-30 11:39:35 -04:00
## Registering to CMS Events
You can execute a function when a specific CMS event occurs.
Example usage:
```javascript
CMS.registerEventListener({
2022-11-04 17:41:12 -04:00
name: 'prePublish',
2022-10-20 11:57:30 -04:00
handler: ({ author, entry }) => console.info(JSON.stringify({ author, data: entry.data })),
2022-09-30 11:39:35 -04:00
});
```
2022-10-01 13:45:01 -04:00
Supported events are `prePublish`, `postPublish`, `preSave` and `postSave`. The `preSave` hook can be used to modify the entry data like so:
2022-09-30 11:39:35 -04:00
```javascript
CMS.registerEventListener({
2022-11-04 17:41:12 -04:00
name: 'preSave',
2022-09-30 11:39:35 -04:00
handler: ({ entry }) => {
2022-10-20 11:57:30 -04:00
return entry.data.set('title', 'new title');
2022-09-30 11:39:35 -04:00
},
});
```
## Dynamic Default Values
When linking to `/admin/#/collections/posts/new` you can pass URL parameters to pre-populate an entry.
For example given the configuration:
2022-11-07 10:27:58 -05:00
<CodeTabs>
2022-09-30 11:39:35 -04:00
```yaml
collections:
2022-11-04 17:41:12 -04:00
- name: posts
2022-09-30 11:39:35 -04:00
label: Posts
folder: content/posts
create: true
fields:
- label: Title
2022-11-04 17:41:12 -04:00
name: title
2022-09-30 11:39:35 -04:00
widget: string
- label: Object
2022-11-04 17:41:12 -04:00
name: object
2022-09-30 11:39:35 -04:00
widget: object
fields:
- label: Title
2022-11-04 17:41:12 -04:00
name: title
2022-09-30 11:39:35 -04:00
widget: string
- label: body
2022-11-04 17:41:12 -04:00
name: body
2022-09-30 11:39:35 -04:00
widget: markdown
```
2022-11-07 10:27:58 -05:00
```js
collections: [
{
name: 'posts',
label: 'Posts',
folder: 'content/posts',
create: true,
fields: [
{
label: 'Title',
name: 'title',
widget: 'string'
},
{
label: 'Object',
name: 'object',
widget: 'object',
fields: [
{
label: 'Title',
name: 'title',
widget: 'string'
}
],
},
{
label: 'body',
name: 'body',
widget: 'markdown'
},
],
},
],
```
</CodeTabs>
2022-09-30 11:39:35 -04:00
clicking the following link: `/#/collections/posts/new?title=first&object.title=second&body=%23%20content`
will open the editor for a new post with the `title` field populated with `first`, the nested `object.title` field
with `second` and the markdown `body` field with `# content`.
**Note:** URL Encoding might be required for certain values (e.g. in the previous example the value for `body` is URL encoded).