We've previously covered creating components by specifying field types. Now, we'll introduce Standard Values, allowing setting default values to streamline editing efforts for content editors.
This feature isn't specific to Sitecore Headless but is a standard Sitecore functionality. If not configured, it's essential to consider suitable settings based on operational needs.
How to set up Standard Value
The Standard Value mechanism can be used when you want to set a standard value for an item when it is created. This can be set in the template definition screen and is set as the initial value when the item is created.
The following pages provide more details.
The first step is to set a text field with the same data as the item name as the data when the item is created. We will use the template /sitecore/templates/Project/sitecoredemo/jp/Data/TextSample that we created previously. The creation of this is introduced in the following page.
Once the target template is specified, the builder options appear in the menu items. When you open the ribbon, you will see the Standard Values and Menu.
Clicking on the menu will create a blank item with the item __Standard Values added as an item one level below the template. This will be the item you define for the initial data when creating a new one.
This time, for the singlelinetext1 item, enter the setting $name and save the standard value.
This completes the initial value setting.
Create another standard value for the template /sitecore/templates/Project/sitecoredemo/jp/Data/DateNumberSample. The value is in the form of $date at the date.
Token
In the above section, we have introduced sudden values in the form of $name and $date, and these parameters are called tokens. Sitecore では以下のトークンが用意されています。
Token | Value |
---|---|
$name | Item Name |
$id | Item ID |
$parentid | ID of the parent item |
$parentname | Parent Item Name |
$date | System date yyyyMMdd |
$time | System time HHmmss |
$now | Date and time yyyyMMMddTHHmmss |
Verification
First, we want to create an item using the TextSample template we just created. This time, we will create an item with the following name.
When created, the item name is entered as is for singlinetext1.
This is an easy way to do this, putting in the name of the item when the item is created. Then create the item using the `DateNumberSample` template.
The finished product will be in the form that today's date is specified in the date section.
Summary
In this article, we introduced the movement of standard values as a way to set initial values when an item is created. In this case, we specified a token in the form of $name $date, but it is also possible to set a standard value. By using this kind of functionality, you can simplify your daily content creation work.