Copied to clipboard

Flag this post as spam?

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


  • Natasha 9 posts 99 karma points
    Sep 13, 2020 @ 22:51
    Natasha
    0

    Using content picker on media type

    Hi I have a Slide media type with custom properties including a content picker. I am able to pick up all the other custom properties using @item.Value(), but I am unable to get the content picker url to work the link goes to a 404 page. My code is below

    @{
        var typedMultiMediaPicker = Model.Value<IEnumerable<IPublishedContent>>("imagesAndText");
        foreach (var item in typedMultiMediaPicker)
        {
        <img src="@item.Url" class="background-image-full overlay overlay--dark" data-cycle-title="@item.Value("title")" data-cycle-desc="Sonnenberg Gardens">
               <a class="button button--border--solid"  href="@item.Value("slideLink")">
                    @item.Value("slideButtonText")
                </a>    
         }
    }   
    

    What am I doing wrong? Please help

    Thanks in advance Nat

  • Ambert van Unen 175 posts 819 karma points c-trib
    Sep 14, 2020 @ 07:34
    Ambert van Unen
    0

    Doing this out of my head, but if you look at the URL that gets returned from @item.Value("slideLink"), it will probably be the Model instead of the URL?

    Perhaps, depended on the Model you get returned (which depends on your configuration for the contentpicker) you'd need something like this?

    @item.Value

  • Natasha 9 posts 99 karma points
    Sep 14, 2020 @ 09:45
    Natasha
    0

    Hi Ambert

    Thanks so much for your reply

    @item.Value("slideLink")
    

    returns http://mysite/Umbraco.Web.PublishedModels.Products

    @item.Value("sideLink").Url
    

    I already tried it throws an error.

    Best wishes Nat

  • Ambert van Unen 175 posts 819 karma points c-trib
    Sep 14, 2020 @ 10:48
    Ambert van Unen
    0

    What is the error that gets thrown?

    I assume you have ContentPicker set to only 1 product being able to be selected? If not, you could have a List of products to be returned, instead of a single 'products' option.

  • Natasha 9 posts 99 karma points
    Sep 14, 2020 @ 10:54
    Natasha
    0

    Hi It's a compilation error public_html\Views\home.cshtml(20,81): error CS1503: Argument 1: cannot convert from 'method group' to 'object' The content picker is for the products page with the listing, but I want the user to be able to pick any page to link it to. It is for a slider rather than a single product.

    Thanks for your help so far.

  • Ambert van Unen 175 posts 819 karma points c-trib
    Sep 14, 2020 @ 11:12
    Ambert van Unen
    0

    So I think you get a list of objects returned, instead of a single item.

    Just to try, you could do:

    @item.Value("sideLink").First().Url

    If that works, it means that you get multiple objects returned, and it can't get the .Url of a list of objects ;-)

  • Natasha 9 posts 99 karma points
    Sep 14, 2020 @ 11:16
    Natasha
    0

    I'm afraid that throws an error too: public_html\Views\home.cshtml(20,104): error CS1061: 'object' does not contain a definition for 'First' and no accessible extension method 'First' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)

  • Ambert van Unen 175 posts 819 karma points c-trib
    Sep 14, 2020 @ 12:00
    Ambert van Unen
    0

    Ah I misinterpreted it a bit, my bad, this will most likely help:

    Try the following:

    @(item.Value<IPublishedContent>("contentpicker").Url)
    

    Not too sure on the how and why this is needed here, but most likely having to do with that the system doesn't know what type of content is being returned.

    In my code I now enforce it to be of "IPublishedContent", so the URL method is applicable here.

  • Natasha 9 posts 99 karma points
    Sep 14, 2020 @ 12:23
    Natasha
    0

    That doesn't work either it throws the same error CS1503: Argument 1: cannot convert from 'method group' to 'object'. I tried with and without additional brackets.

  • Ambert van Unen 175 posts 819 karma points c-trib
    Sep 14, 2020 @ 12:33
    Ambert van Unen
    0

    And when you try this aswell?

     foreach (IPublishedContent item in typedMultiMediaPicker)
    

    I had it giving the correct value with both of the options added.

  • Natasha 9 posts 99 karma points
    Sep 15, 2020 @ 14:49
    Natasha
    0

    Hi Ambert

    I managed to fix it with this code:

    @{
        var typedMultiMediaPicker = Model.Value<IEnumerable<IPublishedContent>>("imagesAndText");
        foreach  (IPublishedContent item in typedMultiMediaPicker)
        {
        <img src="@item.Url" class="background-image-full overlay overlay--dark">
        var link = item.Value<IPublishedContent>("slideLink");
         <a href="@link.Url">ReadMore</a>
         }
    }   
    

    but three links appear on one slide/image rather than one link per slide/image

    Thanks again Best wishes Natasha

  • Ambert van Unen 175 posts 819 karma points c-trib
    Sep 15, 2020 @ 18:17
    Ambert van Unen
    0

    But thats logical right?

    You have 1 slide, and a contentpicker on that slide where you select three different links ;-)

    Better to restrict the contentpicker to one link.

    Then in the content, add a contentpicker, and select 3 different slides. Fixed!

Please Sign in or register to post replies

Write your reply to:

Draft