You can use the DictionaryItem class to get a DictionaryItem from it's ID or Key, then use the Children property to get the children.
var dictionaryItem = new umbraco.cms.businesslogic.Dictionary.DictionaryItem("item1");
foreach (var childItem in dictionaryItem.Children) { ... }
But, I'm not sure how this is going to work for you, because I think the Dictionary is meant for each key to be unique. Otherwise from the front end how are you going to request the text for the key "item1" since it exists twice? You may need to pre/post-fix the values with something to make them unique.
I don't think the Dictionary is meant to work that way.
But you could write your own helper methods to handle it instead of using the built-in umbraco.library.GetDictionaryItem. Split the slash, use the code above to get the "folder1" key, then find the second part in it's children and return that. Not sure if you might run into other issues having duplicate keys though.
Dictionary items are actually nest-able. So You may create a regular dictionary item that will act as a "folder" and then create "child" dictionary items under that. Try installing FALM housekeeping and then go to the dictionary section to see the dictionary items the package has added, and the way they are organized to get the idea.
@dominik
I have already tried your solution and ran into many problems with the front end (umbraco:item and such). I ended up using the parent item names as prefixes, dot separated. So I had
The items in the Dictionary must have a unique key, but can be nested any way that suits your environment. This is great for your code, because you can always get an item just by its unique key, instead of having to address it in the folder its in - it wouldn't be the first time it happened, if you (or your superior) suddenly decided that the dictionary items needed to be restructured and grouped by site instead of function.
check for dictonary item in "subfolder"
hello i use the following dictonary items:
- folder1
- item1
- item2
- folder2
- item1
Now i want to check in c# if the entered text exists in dictonary folder "folder1"
like this:
umbraco.library.GetDictionaryItem("folder1/item1") ;
I can not just use "item1" because this dictonary item exists in both folders.
Thanks
Hi dominik,
You can use the DictionaryItem class to get a DictionaryItem from it's ID or Key, then use the Children property to get the children.
But, I'm not sure how this is going to work for you, because I think the Dictionary is meant for each key to be unique. Otherwise from the front end how are you going to request the text for the key "item1" since it exists twice? You may need to pre/post-fix the values with something to make them unique.
-Tom
hi Tom i want to use it in this way:
umbraco.library.GetDictionaryItem("folder1/item1") ;
and if i want to get item1 in folder2 i can use
umbraco.library.GetDictionaryItem("folder2/item1") ;
thanks
I don't think the Dictionary is meant to work that way.
But you could write your own helper methods to handle it instead of using the built-in umbraco.library.GetDictionaryItem. Split the slash, use the code above to get the "folder1" key, then find the second part in it's children and return that. Not sure if you might run into other issues having duplicate keys though.
-Tom
How did you get dictionary items organized in folders. I have a huge list and the users have a hard time to find the correct key
@Mounhim Tahtahi
Dictionary items are actually nest-able. So You may create a regular dictionary item that will act as a "folder" and then create "child" dictionary items under that. Try installing FALM housekeeping and then go to the dictionary section to see the dictionary items the package has added, and the way they are organized to get the idea.
@dominik
I have already tried your solution and ran into many problems with the front end (umbraco:item and such). I ended up using the parent item names as prefixes, dot separated. So I had
Folder1
Folder1.Item1
Folder2
Folder2.Item1
HTH
Yiangos
HTH
Yiangos
Hi all - just a quick comment:
The items in the Dictionary must have a unique key, but can be nested any way that suits your environment. This is great for your code, because you can always get an item just by its unique key, instead of having to address it in the folder its in - it wouldn't be the first time it happened, if you (or your superior) suddenly decided that the dictionary items needed to be restructured and grouped by site instead of function.
/Chriztian
Hi chriztian,
I am only facing one big issue.
If i have a subfolder where a unique ID already exists and it is created a second time it creates a lot of issues.
It stops also the server from working. At least if you try to delete it.
is there any way to avoid creating the same ID twice?
We cant check 30 or more folders to see if a unique ID already exists
Thanks
is working on a reply...