Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • dominik 711 posts 733 karma points
    May 24, 2012 @ 15:04
    dominik
    0

    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

  • Tom Fulton 2030 posts 4998 karma points c-trib
    May 24, 2012 @ 15:13
    Tom Fulton
    0

    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.

    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.

    -Tom

  • dominik 711 posts 733 karma points
    May 24, 2012 @ 15:14
    dominik
    0

    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

  • Tom Fulton 2030 posts 4998 karma points c-trib
    May 24, 2012 @ 15:17
    Tom Fulton
    0

    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

  • Mounhim Tahtahi 41 posts 62 karma points
    Sep 03, 2013 @ 10:05
    Mounhim Tahtahi
    0

    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

  • Yiannis Vavouranakis 38 posts 78 karma points
    Oct 29, 2013 @ 14:59
    Yiannis Vavouranakis
    0

    @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

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Oct 29, 2013 @ 15:08
    Chriztian Steinmeier
    0

    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

  • dominik 711 posts 733 karma points
    Oct 29, 2013 @ 16:47
    dominik
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft