Copied to clipboard

Flag this post as spam?

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


  • Hammad 1 post 82 karma points notactivated
    Feb 09, 2018 @ 13:06
    Hammad
    1

    Cannot properly add Skybrud.ImagePicker

    I am new to Umbraco, and am trying to add
    Skybrud.ImagePicker

    I have added a Document type, and added the Skyburd Image Picker as a Property in it.

    I went to Content, and in my page added the data from the UI, which looks fine.

    Now I am stuck, as previously I saw that for any text type, I would simply add @Umbraco.Field("Field Name") and that field will be shown. How do I add this Image picker here? If I try adding my field like before it simply prints Skybrud.ImagePicker.ImagePickerList . Which is definitely a type. Maybe I am missing something which is obvious to others. Maybe I need to search some more, but whatever it is please someone guide me in the right direction.

    Thanks,

  • Anders Bjerner 487 posts 2995 karma points MVP 8x admin c-trib
    Feb 09, 2018 @ 16:08
    Anders Bjerner
    101

    Hi Hammad,

    @Umbraco.Field("...") is mostly for getting simple values. You can't get the image picker value this way.

    What you should do instead depends a bit on how your code looks. For instance, if you have a view that inherits from UmbracoTemplatePage, you can do it like this:

    @using Skybrud.ImagePicker
    @using Skybrud.ImagePicker.Extensions
    @inherits UmbracoTemplatePage
    
    @{
    
        //@Umbraco.Field("imagePicker")
    
        ImagePickerList list = Model.Content.GetImagePickerList("imagePicker");
    
        if (list.IsValid)
        {
    
            foreach (ImagePickerItem item in list.Items)
            {
    
                <pre>@item.Image.Url</pre>
    
            }
    
        }
    
    }
    

    The GetImagePickerList is a special extension method from the image picker package. Alternatively you could use the GetPropertyValue instead:

    @using Skybrud.ImagePicker
    @inherits UmbracoTemplatePage
    
    @{
    
        //@Umbraco.Field("imagePicker")
    
        ImagePickerList list = Model.Content.GetPropertyValue<ImagePickerList>("imagePicker");
    
        if (list.IsValid)
        {
    
            foreach (ImagePickerItem item in list.Items)
            {
    
                <pre>@item.Image.Url</pre>
    
            }
    
        }
    
    }
    

    Hope that helps ;)

Please Sign in or register to post replies

Write your reply to:

Draft