Custom Fields
Creating a Custom Field
This walkthrough adds a Recommended custom field called URL Slug to a content type. The code itself is explained in the tutorial; here the focus is the content type editor.
Turn On the New Edit Content for the Content Type#
Open the content type, select Settings, check Enable Edit Content Beta and select Update, as described in Content Editor. Without this, you won't see the Implementation option. The checkbox is per content type and can be turned off again at any time.
Add a Custom Field#
Drag Custom Field from the field list on the right into a row. The field dialog opens.
Name It and Choose Recommended#
Enter a Name. dotCMS creates the field's variable name from it (URL Slug becomes urlSlug); you'll use it in your code. The variable name can't be changed after you save. Under Implementation, select Recommended.
New fields start as Deprecated. The Implementation picker preselects Deprecated. Select Recommended before you save.
Write the Template in Value#
Paste your code into Value. Add a Hint if editors need guidance, and check Required if the content can't be saved without a value.
Name, Implementation and Value are required. Hint, Required and the other options are further down the Overview tab and work as on any other field.
Keep long templates in a file. For longer code, save it as a .vtl file in dotCMS and put only #dotParse("/application/custom-fields/url-slug.vtl") in Value. The same file can then be reused by several fields and kept under version control.
Save, Then Review Settings and Field Variables#
Select Save. When you open the field again, the Settings tab appears and Field Variables becomes available:
- Settings has Hide Label, for fields that show their own label. Recommended fields only have this option.
- Field Variables shows
newRenderMode = component, which is how dotCMS stores your Recommended choice.
All the options are listed in Custom Field Reference.
Open the Content Editor#
Create or edit content of that type. The field renders inline with the editor's own fonts, inputs and buttons.