What are Standard Values in Sitecore? And how they are useful?

As we completed our templates overview and field types in previous blogs, it’s time to learn best practices that we need to keep in mind while designing templates.

Now lets consider a scenario, if you have to create 100 sitecore items from one template and whatever name you give to the item can also be the value for title field of that item. If you think, then you have to do the typing of the name twice so Sitecore has got us something called tokens which we can use in Standard values of that particular item.

There are two types – static and dynamic i.e. we can enter static text in the standard values (like placeholder text in text boxes) and dynamic where we can use tokens and it will take the value entered by the Content Editor.

Tokens available are:
$name: The name of the item
$id: The ID of the item
$parentid: The ID of the parent of the item
$parentname: The name of the parent of the item
$date: The system date (yyyyMMdd)
$time: The system time (HHmmss)
$now: The date and time (yyyyMMddTHHmmss)

Lets try this in our solution.

  1. Go to Sitecore instance (http://learningsitecore/sitecore)
  2. Enter the credentials (admin/b)
  3. Navigate to Content Editor.
  4. Navigate to Templates >> User Defined >> MenuItem.
  5. When you are on MenuItem template, you should be able to see the ‘Builder Option’ tab in the Ribbon.
    27SD1
  6. Click on Builder Options.
  7. Click on Standard values.
    27SD2
  8. Lets use ‘$name’ token in the title field and Save the item.
    27SD3
  9. Now lets create a content item out of this and check if this token works.
  10. Navigate to Navigation folder (/sitecore/content/Home/Navigation).
  11. Right Click >> Insert >> Insert from template
  12. Select the MenuItem template and name the item as ‘Testing token’
    27SD4
  13. Click Insert. And now if you see, the title field is populated with the value which gave for the name of the item.
    27SD5
  14. Standard values are very useful and it is best practice to add the standard values.

Don’t confuse the tokens with standard values. In the standard values you can set many predefined things for an item like presentation details, workflows, insert options, configuring icons etc.

Now we will learn about configuring icons and insert options. Rest we will learn as we reach to those topics.

So we use icons to distinguish the templates it is based on. So all the similar items will have same icon because they are based on the same template. So this clarifies that we need to configure the icon on the standard values. Lets try it out.

  1. Navigate to MenuItem template (/sitecore/templates/User Defined/MenuItem)
  2. Expand the template and navigate to __Standard Values item.
  3. Click on Configure tab in the ribbon and click on the down arrow next to Icon button.
    27SD6
  4. Select the blue star for now. Save the changes.
  5. Lets create an item out of this template.
  6. Navigate to to the Navigation folder (/sitecore/content/Home/Navigation).
  7. Right Click >> Insert >> Insert from template
  8. Select the MenuItem template and name the item as ‘Testing icon’
  9. Click Insert.
  10. Now if you see, all the items based on MenuItem template are having blue star as their Icon.
    27SD7

In the above section, we learnt how to set the icon. This is one of the best practices and helps your content editor to understand the content tree very easily.

Now we will learn about insert options. The insert options means we should have the required template in the list near insert from template option when we right click on the item and select Insert.

Lets consider a scenario where a Submenu will always be under Menu item. So whenever we click on nay Menu item and select Insert, we should have an option to insert SubMenu item.

  1. Create a template SubMenu under User Defined.
  2. Right Click on User Defined >> New Template.
  3. Name it as SubMenuItem
    27SD8
  4. Click Next, Next and Close.
  5. Create a field section ‘Sub Menu Details’ and fields ‘Title’ with ‘Single Lined Text’ type and ‘Link’ with ‘General Link’ type
    27SD9
  6. Lets set the standard values which we have learned. $name for title and Green star as an Icon.
  7. Click on Builder Options in the ribbon
  8. Click on Standard values.
  9. Enter the $name in Title. Set Green star as an icon.
    27SD10
  10. Navigate to __Standard Values item under MenuItem template (/sitecore/templates/User Defined/MenuItem/__Standard Values).
  11. Click on View tab, Check the Standard fields check box.
    27SD11
  12. Now scroll down till you find the Insert Options section.
  13. Click on Edit link under Insert Options field.27SD12
  14. Navigate to SubMenuItem template and double click on it.
  15. Click OK and Save the changes.
  16. Lets see if we are getting an option to insert SubMenu item if are on Menu Item.
  17. Navigate to any Menu Item (/sitecore/content/Home/Navigation/Testing Icon)
  18. Right Click >> Insert >> SubMenuItem, which means we can directly insert the items based on SubMenuItem template under Menu items now.
    27SD13.png

This completes our Standard values and its uses for the sections, we have previously covered. For setting up presentation details and workflows, we will do it once we are done with those topics.

Thank you.. Happy Learning.. Happy Sitecoring.. šŸ™‚

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s