Copied to clipboard

Flag this post as spam?

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


  • Fredrik Hansson 16 posts 36 karma points
    Jan 14, 2012 @ 00:10
    Fredrik Hansson
    0

    Using Url Picker as data type on media type?

    Hello everyone,

    IƤve added the Url picker to my image media type, so that images used in a slideshow can be linked. However, it seems the url picker only returns a string. Can't the url picker be used on an image?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 14, 2012 @ 06:46
    Jan Skovgaard
    0

    Hi Frederik

    I suppose the url picker returns a string with either the id of the picked node or the path?

    Then you must wrap the value in an a element around your image.

    Can you perhaps share yoour code with us?

    /Jan

  • Fredrik Hansson 16 posts 36 karma points
    Jan 14, 2012 @ 10:07
    Fredrik Hansson
    0

    It returns all the values in the object as a string (which seems wierd...). Here's my code

    dynamic folder Model.MediaById(Model.slideShow);

            <ul id="topslider">
                @foreach (dynamic slide in folder.Children
                {
                    <li>
                            <href="@slide.imageLink">
                                <img src="@slide.umbracoFile" />
                            </a>
                    </li>
                }
            </ul>

    I've used a Media picker to point to a folder with images.

  • Ian Robinson 79 posts 143 karma points
    Jun 19, 2012 @ 12:59
    Ian Robinson
    0

    I'm having the same issue.  Upgraded from 4.7.1 to 4.7.2 but it made no difference.  Did you find a solution Fredrik?  I've done this before on normal document type, so is there something strange about using it on a media type?

    My media doc type has an "umbracoFile" property and a "link" property.  I can get the umbracoFile property out, but not the link property, which is using a uComponents URL picker set to a data format of xml.  I'm trying to retrieve the url inside the link property but I get the error:

    Error Loading Razor Script (file: Insert Type 1 Banner Image) 'string' does not contain a definition for 'url'    at CallSite.Target(Closure , CallSite , Object )
      at ASP._Page_macroScripts_InsertType1BannerImage_cshtml.Execute() in d:\Web_Applications\Dev_Umbraco_Intranet\macroScripts\InsertType1BannerImage.cshtml:line 41
      at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
      at System.Web.WebPages.WebPage.ExecutePageHierarchy()
      at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
      at umbraco.MacroEngines.RazorMacroEngine.ExecuteRazor(MacroModel macro, INode currentPage)
      at umbraco.MacroEngines.RazorMacroEngine.Execute(MacroModel macro, INode currentPage)

    Using this code:

         var slideshowFolder= Model.MediaById(Model.GetPropertyValue("slideshow"));

        var uniqueId = "slideshow_" + slideshowFolder.Id;
        var images = slideshowFolder.Children;

        <div id='@uniqueId' class="minimal_galleria"  style="background-color: transparent; height: 296px; width: 410px;">
     
        @*
          for each image
        *@
        @foreach (var item in images)
        {
     
            if (item.HasValue("link"))
            {
                    <p>@item.link.url</p>
            }

        }
        </div>

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jun 19, 2012 @ 13:45
    Tom Fulton
    0

    Hi Ian,

    Do you maybe have your URL Picker datatype set to store the value as CSV or JSON instead of XML?  In this case .url wouldn't be valid since it's not XML (which converts to DynamicXml)

    -Tom

  • Ian Robinson 79 posts 143 karma points
    Jun 19, 2012 @ 14:07
    Ian Robinson
    0

    Thanks Tom, but I've double-checked and it's set to XML.

  • Ian Robinson 79 posts 143 karma points
    Jun 19, 2012 @ 14:15
    Ian Robinson
    0

    If have two slideshow images, both with populated umbracoFile properties, but only one image has a populated link property.  If I change " <p>@item.link.url</p>" to just " <p>@item.link</p>", i.e. removing the .url, I get this output:

    Falsehttp://www.google.co.uk

     

    False

    It looks as it if isn't outputting it as xml.

    Here is my url picker configuration from my data types section:


  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jun 19, 2012 @ 19:57
    Tom Fulton
    0

    Hi Ian,

    I took a further look and it seems I get the same issue.  I think when on a Media node, the data is not getting cast to DynamicXml for some reason.

    As a workaround though, you can use the Deserialize function built into the Url Picker to get a strongly typed object with the values:

    var state = UrlPickerState.Deserialize(item.link);
    <a href="@state.Url">....</a>

    You'll need to add a using statement to have access to that also:

    @using uComponents.Core.DataTypes.UrlPicker.Dto

    HTH,
    Tom 

  • Ian Robinson 79 posts 143 karma points
    Jun 20, 2012 @ 10:22
    Ian Robinson
    0

    Thanks Tom,

    I've put in the code you've supplied above but I'm still getting a couple of errors.

    I had to change "UrlPickerState.Deserialize(item.link)" to "UrlPickerState.Deserialize(item.link.ToString())", because it was complaining about the method not receiving the right argument type.  That error has now gone but I'm getting a null reference error.  It might be because one of the images I've put in the system has a link while the other doesn't, so maybe I need to check if state.Url is populated?  I need to get something out of the way this morning and then I'll take another look.

    I appreciate your help!

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jun 20, 2012 @ 14:32
    Tom Fulton
    0

    Hi,

    Looking further, it seems there is something funny going on with Razor when accessing that datatype from a media item.  On a content node it returns DynamicXml but on a media node it's seeming to return a string with the XML stripped out - so that's not going to be parseable by the Deserialize method.

    To get to the root cause we'd need to do some digging/debugging in DynamicNode

    If you need a quick solution, you could use XSLT, or since you're ignoring the "New Window" option anyway, just replace False with "" to get the URL, ie:

    var myUrl = Model.link;
    <a href='@myUrl.Replace("False", "")'>link</a> 

    -Tom

  • Ian Robinson 79 posts 143 karma points
    Jun 20, 2012 @ 14:48
    Ian Robinson
    0

    Thanks for looking into this for me Tom, you've saved me a lot of further frustration!

    I think both options are good, and I think I'll create an XSLT script.  I'd hate to put in a workaround in the Razor script, then the url functionality is fixed in a later version of Umbraco, returning xml, because that might break any workaround I've coded in.

    I'll also log this as an Umbraco 4 razor issue on the Codeplex site (http://umbraco.codeplex.com/workitem/list/basic), and maybe someone will have chance to fix it at some point.

    Thanks again!

Please Sign in or register to post replies

Write your reply to:

Draft