Copied to clipboard

Flag this post as spam?

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


  • David 1 post 71 karma points
    1 week ago
    David
    0

    Datatype with editable values

    Hi,

    I have a Document Type and want to add a multi-select property to this (eg with prevalues such as 'Transport', 'Bridgeworks', 'Marine' etc). I could do this using a Checkbox list Datatype but if later on I want to update the description of an item in the list (eg change 'Marine' to 'Marine and waterways' ), any Documents that had 'Marine' selected will loose this assignment.

    How can I have a multi-select property and the ability to change the description of the values later on?

    Many thanks David

  • Marc Goodson 1350 posts 9103 karma points MVP 5x c-trib
    7 days ago
    Marc Goodson
    1

    Hi David

    What I'll often do in this scenario is create a new Document Type to represent each 'Category', and another Document Type to create them in, eg perhaps called Category Folder.

    These Document Types won't have templates themselves.

    And the Category Document Type won't 'need' to have any properties (to begin with - though I always find after a while that I tend to add some other requirements, like 'category colour' etc etc)

    Then I'll create a Multinode Tree Picker to add to the Document Type that needs to pick the categories, you can configure this to allow multiple category items to be picked, with a starting node of the Category Folder.

    What gets stored for this property when categories are picked, are the Ids of each category node - which means you can change the name of the Category underneath the Categories Folder, and update all the articles that have got that category picked, because the association is via Id.

    Depending on if you are using Modelsbulder or not, you can get a reference to all the picked categories, if the alias of Category Picker is categoryPicker like so:

    Modelsbuilder

    @{
      var categories = Model,CategoryPicker;
    }
    

    or non Modelsbuilder

    @{
      var categories = Model.Value<IEnumerable<IPublishedContent>>("categoryPicker");
    }
    

    write out the categories

    @foreach (var category in categories){
    <li>@category.Name</li>
    }
    

    The only consideration here is if there are thousands of categories, it will make the Umbraco Published Cache disproportionately large.

    Editors can be permitted to create new Categories themselves, or prevented from doing so using permissions if you prefer.

    regards

    Marc

Please Sign in or register to post replies

Write your reply to:

Draft