Copied to clipboard

Flag this post as spam?

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


  • Fredrik Fridsten 3 posts 83 karma points
    Feb 09, 2018 @ 08:33
    Fredrik Fridsten
    0

    Get all uTaxonomy options on one page

    Hi,

    I'm working on a project, where we will allow the user to filter content. The filter tags are hierarchical, which is why we chose to use uTaxonomy. Setting the filter tags for the content in a partial view works fine, but we also would like to show all the possible filter tags in a filter module. Is there a way to access all uTaxonomy values and present them to the user? Sorry for being vague here, I've just started using Umbraco and Razor templates.

    Thanks! /Fredrik

  • Vitaly Vasilega 62 posts 184 karma points
    Feb 09, 2018 @ 14:46
    Vitaly Vasilega
    0

    Hi Fredrik,

    Yes you can get all items if you know datatype name.

    You can find more information here

    In my opinion, you need to use

    var items = TaxonomyService.GetTaxonomyTree("Gender");
    

    or

    var items = TaxonomyService.FlattenList("Gender");
    

    First code returns hierarchical structure, the second code returns flatten list.

    I hope I helped you!

    Thanks

  • Fredrik Fridsten 3 posts 83 karma points
    Feb 09, 2018 @ 15:06
    Fredrik Fridsten
    0

    That only seems to work if you have added the taxonomy to the particular partial view. What we would like to do is get all the available options, regardless of whether they have been selected or not, and present them to the user in a different partial view.

    I have a "Content" partial view, where the editor/admin can select (and sometimes manipulate) a taxonomy hierarchy (for example Country - State - City).

    Then there is another "Filter" partial view, where we would like the user to see all the available taxonomy content, regardless of whether it has been selected for the content or not, i.e. all countries, all states and all cities.

    The solution you suggested doesn't seem to work for me. :/

  • Vitaly Vasilega 62 posts 184 karma points
    Feb 09, 2018 @ 15:36
    Vitaly Vasilega
    100

    Not exactly!

    When you add new Taxonomy, you add it in Data Types section.

    It means that this Taxonomy not bound with concrete Document type!

    In turn, this means that the code, which I gave you as an example gets all the items from the Taxonomy by Datatype name.

    Thanks, Vitaly

  • Fredrik Fridsten 3 posts 83 karma points
    Feb 12, 2018 @ 08:27
    Fredrik Fridsten
    0

    It's working now! I took a second look and realized that I had been confused with the Datatype name and the title of it on the partial view. Thanks a lot! :)

  • Vitaly Vasilega 62 posts 184 karma points
    Feb 12, 2018 @ 08:49
    Vitaly Vasilega
    0

    Your are welcome!

Please Sign in or register to post replies

Write your reply to:

Draft