1

I have to create a list of all the countries available because I need the list for a dropdownlist in multiple custom forms. So I tried to create this list in the sitecore dictionary, but I don't know how to access this dictionary and get all items under the "Countries" folder (dictionary folder) into my MVC project.

enter image description here

Is this possible or is there any better solution where I could locate this list?

Using Sitecore 8.2 with Glassmapper.

3
  • When you say you need to access this from Forms, do you mean Sitecore Forms or just a drop down in another item?
    – Chris Auer
    Feb 13, 2020 at 18:38
  • I mean I have to access this from a custom form. I am also using Glassmapper.
    – dave_26456
    Feb 14, 2020 at 6:12
  • I would just create a Country template and create the countries some place else in the content tree. Fx. create a Configuration folder under the site and put the countries in there.
    – ebug
    Feb 14, 2020 at 7:44

3 Answers 3

2

Do not store the list of content items (in your case countries) in Dictionary. Rather have a folder called Countries in your DataRepository (Or GlobalContent) folder. Within this folder, you should create your country items (you can create a basic template for with key, value, country flag etc. fields to create these items).


In your dropdown field, give the Countries folder as datasource.

0

If you just want to use this as data for a custom form, remember that at their core, any object in Sitecore is an Item object. You should be able to do a GetItem on the Countries folder by specifying its ID, and then do a Children retrieval from there. You could use Glass Mapper for this, but then you'd have to do a model/map for the dictionary objects, when in your case you likely just want to read into a C# Dictionary for the key/value pair...one of those instances Glass may not be the right tool.

If you want to use Sitecore Forms, you may have to alter your approach. Check out the documentation on dynamic dropdown fields here: https://doc.sitecore.com/users/90/sitecore-experience-platform/en/add-list-items-for-forms.html

2
  • I am using Glassmapper but i can't access the dictionary because it's under "System". The Question is updated with a screenshot.
    – dave_26456
    Feb 14, 2020 at 6:18
  • You can have a dictionary anywhere in the tree, if you create a starting item (or copy/move your node). What kind of error do you get if you try to do a GetItem on that Countries node? Feb 14, 2020 at 19:22
0

You need to use Translate method to localize dictionary entries to langugae which current visitor is switched to.

This method in your case has one parameter which is Dictionary key: Translate.Text([key])

You need to do two steps in your backend code when accessing these values:

  1. Get list of all keys under Countries folder (Glassmapper can do it for you)
  2. Iterate through this list with Translate.Text([key]) method where Key will come from first step

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.