So this blog will be the continuation of the previous blog, where we completed the first 4 categories and now we will concentrate on the remaining 3. Those categories are:
- Link
- Drop down
- Multi values
So to start learning these categories, we will need to create one more custom template. By now I am sure, you know to create a custom template. SO lets do it once again.
- Go to Sitecore (http://learningsitecore/sitecore)
- Enter your credentials (admin/b)
- Go to Content Editor interface.
- Expand Templates item
- Select User Defined (/sitecore/templates/User Defined)
- Right Click >> Insert >> New Template
- Name it “Field Types2” and Click Next
- Again click Next and Close.
- Now you will get a template creation screen.
- Lets create 3 sections for different categories and different field types under each category.
- Now we have created 2 Categories – Link Category and Drop Down Category
- Lets create Multi value category as well.
- Now I will deep dive in each and every field.
- For Link category, we have 2 types of fields type – internal link and General link.
- As the name states, we can use internal link only when we are sure that we will be redirecting the user within the site like Home, About, Services, Contact us, etc. We can use General link when we are not sure whether it will be internal link or External link or mail to function like in the case of CTAs.
- For Drop down category, again we have 2 field types – Droplink and Droplist. To understand it better, please go through below write up and I will explain this when we create dummy site.
Droplist field type:
The value is stored in Sitecore as plain text representing the display name of the selected item. In this case you could use your code sample to render out the name of the selected item (if that’s really what you want to do).
*Note that the content editor will use the Display Name of the items in the droplist, but your code would render out the item name. This is not a good practice as it is not possible to translate item names.DropLink field type:
The value is stored in Sitecore is an ID of the linked item. In this case you would need to get the selected item using this ID, then render out the required field of that item. I would probably write a code-behind method to get the selected item. - Don’t need to stress yourself, both the field types does the same thing, helps you select single item from the list of items. But it further differs if you need the item Name or you need any other field from the selected item.
- Now as we are discussing about selecting a single item from the list of items, how will the drop down fields know which list to display?
- For that we have a “Source” field in front of each field type.
- Lets give Menu as the list of items to both the drop down fields.
- Lets note the path of Navigation folder (/sitecore/content/Home/Navigation).
- Now the value of path, we will paste in Source field of both drop down fields.
- How it is rendered in item we will check once we are done with our 3rd category.
- In the multi value category, we have 5 different field types namely CheckList, Multilist, Multilist with Search, TreeList and TreeListEx.
- The purpose of all the field types is same, to allow you to select multiple values from the list of items. The difference is the way this fields are rendered in the item.
- Since we need list of items, we will enter the path of Navigation in Source field of all fields. But for add Source field for Mulitlist with Search, it is bit different.
- We should note the id of Navigation folder ({31C1994A-3AB9-4CF0-8A26-32CAC7E8FAA6}) and Id for the MenuItem template ({AE6600D5-5C68-4D7C-9674-D29E34D2BF7C}) as all the Menu items (Home, About, Services, etc are based on MenuItem template).
- The source field content will be “StartSearchLocation={31C1994A-3AB9-4CF0-8A26-32CAC7E8FAA6}&TemplateFilter={AE6600D5-5C68-4D7C-9674-D29E34D2BF7C}”
- The ids in my blogs and your instance can be different. So the id of your navigation folder will come in StartSearchLocation and your MenuItem template’s id will come in TemplateFilter.
- Now that we are done with template. Save the changes.
- Lets create a content item based on this item and check.
- Go to Home item (/sitecore/content/Home)
- Right Click >> Insert >> Insert from template
- Navigate to the “Field Type2” template and give Demo2 as Item Name.
- Click Insert.
- Now we have 4 sections out of which we have created 3 sections and 1 is Quick Info where we can get Id, Name, Template id and Path of the current item.
- Lets see Link Category section.
- Now if we see, for Internal link we get only 2 options to insert link and clear and for General link we get different options to select the link.
- Lets see the drop down category section.
- Both the fields render same way and we can’t see the difference. But the difference is when we will try to get the selected item in the back end. One will give us a plain text and other will return us an item so we can get value of any field of that particular item. We can see that while building the site.
- Lets see the Multi value category section.
- So these shows how the different field types are rendered. All gives you a same functionality of selecting multiple items from the list of items but the way of representing it is different.
This completes our part II of the field types. Hope you are not bored with the series and we will see something called standard values in our next blog.
Thank you.. Happy Learning.. Happy Sitecoring ๐
Pingback: What are different types of Field types in Sitecore? – Part I | Sitecore Dairies
best content ever..thanks rohan for ur hardwork to get prepare this blogs
LikeLiked by 1 person
I am glad that you liked it.. ๐
LikeLike