Preview of custom MediaData

Member since: 2007

Hi,

I've done a custom IContent implementation that inherits from MediaData. How can I create a custom preview view for these objects?

This is what I have right now, and that's not working:

[TemplateDescriptor(
    AvailableWithoutTag = true,
    Inherited = true,
    Tags = new[] { RenderingTags.Preview })]
public partial class MyCustomPreview : PreviewPage, IRenderTemplate<MyCustomData>, IRenderTemplate
{
}

When I double click or chose Edit on an object it goes directly to All Properties View.

#114267 Dec 08, 2014 22:18
  • Member since: 2007

    Bump!

    #114580 Dec 16, 2014 3:28
  • Member since: 2012

    Do your custom media have its own controller and a view? Because if it has'nt a view it will go to the all properties view.

    I have a custom mediatype, ImageFile that inherits from a base class, like this  (public class ImageFile : MediaBase, IContentImage) . The base class (MediaBase) inherits from mediadata.

    #115033 Jan 08, 2015 10:51
  • Member since: 2007

    So, I have two views; one for when the content is inside e.g. a content area and that works well, and then I have a http handler for the preview. The preview handler works great if I navigate to it "manually". However, it seems like something is missing in edit mode since this view is not loaded.

    My custom route for edit mode:

    RouteTable.Routes.MapContentRoute(
        name: "ArkenaMediaEdit",
        url: CmsHomePath + "/arkena/{language}/{medianodeedit}/{partial}/{action}",
        defaults: new { action = "index" },
        contentRootResolver: (s) => root.ContentLink);

    And this is my view:

    public class ArkenaPreviewHandler : IHttpHandler, IRenderTemplate<ArkenaVideo>, IRenderTemplate

    My view renders a simple html page with embed code for the video and this view works if I navigate to it "manually".

    I also have a route without the language node, since my media data doesn't support that:

    RouteTable.Routes.MapContentRoute(
        name: "ArkenaMedia",
        url: "arkena/{node}/{partial}/{action}",
        defaults: new { action = "index" },
        contentRootResolver: (s) => root.ContentLink);

    #115065 Edited, Jan 08, 2015 18:19
  • Member since: 2007

    ... and CmsHomePath looks like this:

    private static string CmsHomePath
    {
        get
        {
            return Paths.ToResource("CMS", "Content").Substring(1);
        }
    }

    #115066 Edited, Jan 08, 2015 18:23
  • Member since: 2007

    Some futher investigation... http://domain.local/episerver/CMS/Content/arkena/en/categories/category-1/category-2/test-movie,,1585__providerKey?epieditmode=True doesn't work. But if I remove ",,1585__providerKey?epieditmode=True" from the address the content and my preview is loaded, so http://domain.local/episerver/CMS/Content/arkena/en/categories/category-1/category-2/test-movie works fine.

    #116354 Jan 28, 2015 23:54
  • Member since: 2007

    Ok, seems like my route for viewing the content is unnecessary, the default one seems to work. But still, preview doesn't work, just getting "Preview is not available for this item." Makes me think there is something wrong with the view, but it's weird that it works for viewing the item.

    #116355 Jan 29, 2015 0:20
  • Member since: 2004

    It could be that your preview template is defined as a partial template rather than a page template. You can try to explicitly define it as a page template by adding

    TemplateTypeCategory=TemplateTypeCategories.WebFormsPage

    to your TemplateDescriptorAttribute

    #116359 Jan 29, 2015 9:19
  • Member since: 2007

    Can't edit my first post, but since then I've changed the render template to a HttpHandler. But I added TemplateTypeCategory to the TemplateDescriptor and tried with both WebForm and HttpHandler with no luck :(

        [TemplateDescriptor(
            TemplateTypeCategory = TemplateTypeCategories.HttpHandler)]
        public class ArkenaPreviewHandler : IHttpHandler, IRenderTemplate<ArkenaVideo>, IRenderTemplate

    #116398 Jan 29, 2015 15:56
  • Member since: 1996

    Hi

    If you try

    [TemplateDescriptor(

    Inherited = true,

    TemplateTypeCategory = TemplateTypeCategories.MvcController, //Required as controllers for blocks are registered as MvcPartialController by default

    Tags = new[] { RenderingTags.Preview, RenderingTags.Edit }, Default = true,

    AvailableWithoutTag = false)]

    publicclassMediaDataPreviewController : ActionControllerBase, IRenderTemplate<MediaData>

    {

    public ActionResult Index(MediaData currentBlock)

    {

    .....

    }

    }

    It will trigger when you goto edit mode

    #116446 Jan 30, 2015 8:14
  • Member since: 2004

    I am not sure if this helps but this is how our defualt ones for image looks like for preview:

    [TemplateDescriptor(
            Inherited = true,
            AvailableWithoutTag = false,
            TagString = RenderingTags.Preview,
            TemplateTypeCategory = TemplateTypeCategories.HttpHandler
        )]
        public class ImagePreviewHandler : MediaPreviewHandlerBase, IRenderTemplate<IContentImage>
        {
        }

    and for edit it looks like:

     [TemplateDescriptor(
            Inherited = true,
            AvailableWithoutTag = false,
            TagString = RenderingTags.Edit,
            TemplateTypeCategory = TemplateTypeCategories.MvcController
        )]
        public class ImageEditController : MediaEditController<IContentImage>

     

    #116453 Jan 30, 2015 9:44
First   1 2   Last