Widget Template - Modifying output of AssetsField control

Posted by Community Admin on 04-Aug-2018 09:21

Widget Template - Modifying output of AssetsField control

All Replies

Posted by Community Admin on 14-Jun-2012 00:00

I'm displaying an AssetsField control on the details-widget template for a custom module (projects). it looks like this

<sf:AssetsField ID="download" runat="server" DataFieldName="Download" />

By default, the link that is displayed has link text matching the file-name of the document. What I want instead is for the link to say "Download Project Info Sheet" instead of "filename.pdf". Is this possible with the AssetsField control? 

Posted by Community Admin on 28-Nov-2012 00:00

What is the resolution to this?  I haven't yet found documentation for how to accomplish exactly what the original poster was doing.

Posted by Community Admin on 30-Nov-2012 00:00

Hi guys,

The default AssetsField control does not provide such functionality, so you will need to create a custom one.

What you need to do is to create a class, inherit from AssetsField and replace the template of the control with a custom one. Here is what your code should look like:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Telerik.Sitefinity.Web.UI.Fields;
 
namespace SitefinityWebApp
    public class CustomAssets : AssetsField
    
        protected override string ScriptDescriptorTypeName
        
            get
            
                return typeof(AssetsField).FullName;
            
        
 
        public override string LayoutTemplatePath
        
            get
            
                return layoutTemplatePath;
            
            //set
            //
            //    base.LayoutTemplatePath = value;
            //
        
 
        public string layoutTemplatePath = "~/AssetsFieldCustomTemplate.ascx";
    

When you're using the document mode of the AssetsField control, the link to your document is displayed in the template of the AssetsField by a documentLink control (which is a Sitefinity control):

<sf:DocumentLink id="documentLink" runat="server" />

You can get to it with code behind and modify it from there. 

You can find the AssetsField's default template attached to this response or in our SDK by navigating to Content->Resources->WidgetTemplates.zip.

Kind regards,
Pavel Benov
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items

This thread is closed