Copied to clipboard

Flag this post as spam?

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


  • Bijesh Tank 192 posts 419 karma points
    Aug 31, 2012 @ 13:41
    Bijesh Tank
    0

    Content Picker in media - Razor

    What I'm trying to do is return the URL of a contentpicker inside a media item. I've searched through the forum and seem to be using the various answers that are posted but getting an error...confused! I assume using umbraco.library.NiceUrl would work but no dice. Here's my script below if anyone point out what I'm doing wrong

    @using DigibizAdvancedMediaPicker
    @using umbraco.MacroEngines   
    @using umbraco.cms.businesslogic.member;     
    @using umbraco.cms.businesslogic.media;                                             
    @inherits umbraco.MacroEngines.DynamicNodeContext                                          
    @{
    
    
        var promoBlocks = @Model.AncestorOrSelf(1).DescendantsOrSelf("HomepagePromoBlock");
    
        @*promoBlocks.Count()*@
    
        foreach (var promo in promoBlocks)
        {    
            if (promo.HasAccess())
            {
                @*<p>@promo.Name</p>*@
    
                if (promo.hotspots != null)
                {
                    var mediaIds = promo.hotspots.Split(',');
    
                    foreach (string mId in mediaIds)
                    {
                        dynamic mediaItem = new DynamicMedia(Int32.Parse(mId));
                        dynamic hotspotImage = new DynamicMedia(Int32.Parse(@mediaItem.hotspotImage));
    
                        <a href="@umbraco.library.NiceUrl(mediaItem.hotspotLink)" title="@mediaItem.Name"><img src="@hotspotImage.umbracoFile" alt="image" /></a>
                    }
                }
                return;
            }
        }
    }
  • Bijesh Tank 192 posts 419 karma points
    Aug 31, 2012 @ 13:47
    Bijesh Tank
    0

    Just to add, I can return the node ID of the contentpicker without a problem but as soon as I try to add NiceUrl it errors

    href="@mediaItem.hotspotLink ---> RETURNS: www.domain.com/1084
    href="@umbraco.library.NiceUrl(mediaItem.hotspotLink) ---> RETURNS: Error loading MacroEngine script (file: HomepageHotspots.cshtml)
  • Rich Green 2246 posts 4006 karma points
    Aug 31, 2012 @ 14:41
    Rich Green
    0

    hotspotLink should be returning an ID of a node not a URL.

    If it'snot then something is wrong, nothing to do with umbraco.library.NiceUrl, which expects an integer.

    Are you using the standard in built Content Picker?

    Rich

     

  • Bijesh Tank 192 posts 419 karma points
    Aug 31, 2012 @ 15:39
    Bijesh Tank
    0

    Ah yeh got it, now it works. This is what I did

    var incentiveUrl = @Model.NodeById(mediaItem.hotspotLink);
    <a href="@incentiveUrl.Url" title="@mediaItem.Name"><img src="@hotspotImage.umbracoFile" alt="image" /></a>

     

    Thanks,

    Bij

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies