How to get display a link to a Media field with custom link text
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
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
Thanks Nikola,
Is there any way to get the URL itself inside the widget template? Something like <%# Eval("MediaUrl") %> ?
Thanks,
Dave
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(
"."
,
""
);
...
<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>
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" />
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