+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / How to get display a link to a Media field with custom link text

How to get display a link to a Media field with custom link text

6 posts, 0 answered
  1. Dave
    Dave avatar
    76 posts
    Registered:
    10 Mar 2008
    01 Apr 2014
    Link to this post

    Hi,

     We are using the AssetsField control in a widget template to display a link to a Media item.  By default it seems to use the Media item's title/filename.  Is there a way to have it use another field for the title instead?  Or, alternatively, a way to get just the URL to the Media item so we can craft our own link markup?

     Thanks!

    Dave

  2. Nikola Zagorchev
    Nikola Zagorchev avatar
    424 posts
    Registered:
    24 Nov 2016
    03 Apr 2014
    Link to this post
    Hi Dave,

    Unfortunately, there is no property you can add to the markup from the template. However, the good news are that as most of the Sitefinity controls, the assets field is highly extendable and customizable. You can create your custom control that inherits the AssetsField and override its LayoutTemplatePath or other properties, as well. You can find more information here, as well as, the original template as a road map for customization.

    Regards,
    Nikola Zagorchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  3. Dave
    Dave avatar
    76 posts
    Registered:
    10 Mar 2008
    03 Apr 2014 in reply to Nikola Zagorchev
    Link to this post

    Thanks Nikola,

    Is there any way to get the URL itself inside the widget template?  Something like <%# Eval("MediaUrl") %> ?

     Thanks,

    Dave

  4. Nikola Zagorchev
    Nikola Zagorchev avatar
    424 posts
    Registered:
    24 Nov 2016
    04 Apr 2014
    Link to this post
    Hi Dave,

    Please, refer to this forum thread to see what you have to implement in your custom AssetsField after inheriting from the base. It is shown how to get and set the document url and the title of the link.
    You can find this forum thread helpful, as well.
    I recommend using the following approach for getting the thumbnails for the documents:
    protected virtual Label Thumbnail
            {
                get
                {
                    return this.Container.GetControl<Label>("thumbnail", true);
                }
            }
     
    protected override void OnPreRender(EventArgs e)
            {
                base.OnPreRender(e);
       ...
                            this.Thumbnail.CssClass = "sfdownloadDetails sf" + document.Extension.Replace(".", "");
     
    ...
            }

    and the following css:
    <style>
        .sfdownloadDetails {
        background: url("/WebResource.axd?d=v4CAegCSzP5VshqWP8cglV-ZyQ-hRY4dPcSAi0VUTkmbkr47XqdVfNIgaMc6SxjBb3Oe2ctjdyZyPxdUG0d1RvMZB_3pqCfzxRhiKWMZJasnmPVpE70wbQBhGXjbOr3-bddxF7fA8-cR078xp4ScB8DotixO1B3jS5jy7V129Uf6udiagwg73dillFCIFVgqWXD6y0YV8N0-Qer4YnlUwg2&t=635228974320000000") no-repeat scroll 0 0 rgba(0, 0, 0, 0);
        display: inline-block;
        padding: 3px 0 15px 50px;
        width:30px;
        height:30px;
    }
    .sfpdf {
        background-position: 0 -100px;
    }
    .sfdoc {
        background-position: 0 -200px;
    }
    .sfrtf {
        background-position: 0 -300px;
    }
     .sftxt {
        background-position: 0 -400px;
    }
    .sfxls {
        background-position: 0 -500px;
    }
    .sfdocx {
        background-position: 0 -1600px;
    }
    .sfxlsx {
        background-position: 0 -1700px;
    }
    .sfcsv {
        background-position: 0 -1800px;
    }
     
    </style>
    You can add the different extensions, as well.

    Hope this helps.

    Regards,
    Nikola Zagorchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  5. Dave
    Dave avatar
    76 posts
    Registered:
    10 Mar 2008
    04 Apr 2014 in reply to Nikola Zagorchev
    Link to this post

    Hi Nikola,

    I found out that the ToolTip property seemed to do accomplish what I was looking for.  I ended up with with this markup:

     

    <sf:AssetsField ID="afDownload" runat="server" ToolTip='<%# Eval("Title")%>' DataFieldName="Download" />

  6. Nikola Zagorchev
    Nikola Zagorchev avatar
    424 posts
    Registered:
    24 Nov 2016
    07 Apr 2014
    Link to this post
    Hello Dave,

    Thank you for sharing your way of solving the issue. You can still extend the widget for deeper customization in the future and I hope the information I suggested was helpful and sufficient.

    Regards,
    Nikola Zagorchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
6 posts, 0 answered