Try our conversational search powered by Generative AI!

How to render media dragged directly from the assets pane?

Vote:
 

Hi,

I'm quite new to EPiServer (recently done the fundamentals course) but I noticed you can actually drag images and other media directly from the assets pane into a content area - which seemed kinda neat. However what I've not been able to figure out is how to create a template off of it.

What I end up with is a User Control inheriting from ContentControlBase<ImageFile> with ImageFile itself inheriting from ImageData. However on the course I've not worked with ImageData directly for rendering it has been ContentRefernce or Url types on page and block types and using the EPiServer:Property tags, and I've not really been able to figure out the best way to generate the image tag directly.

I suppose I'm also concerned with making sure it respects any permissions and such that might be controlling who can access the file.

Anyone have any tips or resources I should look at that might help me out?

Thanks,

Mark

#82993
Mar 24, 2014 12:50
Vote:
 

Managed to figure it out after seeing that dragging and dropping media worked in the Alloy demo (was testing in the training project at first).

Key seems to be injecting the UrlResolver.

    [TemplateDescriptor(Inherited = true)]
public partial class Image : ContentControlBase<ImageFile>
{
    protected Injected<UrlResolver> UrlResolver { getset; }
 
    protected string ImageUrl
    {
        get { return UrlResolver.Service.GetUrl(CurrentData.ContentLink); }
    }
 
    protected void Page_Load(object sender, EventArgs e)
    {
        DataBind();
    }
}

<img src="<%# ImageUrl %>" />

 

#82997
Mar 24, 2014 13:06
Vote:
 

You can also use UrlResolver.Current.GetUrl as well without injection in 7.5

#83103
Mar 25, 2014 18:24
Vote:
 

Fab, that's good to know. Thanks!

Think I've got a lot more reading and discovering to do to get the hang of this.

#83122
Mar 26, 2014 10:28
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.