Ticket

Help with Shape Name

I have a custom Admin template for a custom application and I'd like to override the Admin Content Edit shape for only a particular type (Media Item...image to be specific).

I can override the Admin Content Edit shape for everything using:

/ThemeFolder/Views/Contents/Admin/Edit.cshtml

Is it possible to make this shape specific to just the Media or Image type? If so, what would the filename look like?

Thanks!

Re: Help with Shape Name

The issue is that all editor shapes are of type EditorTemplate, which itself renders the appropriate Razor editor template view based on the specified TemplateName property. So what you would have to do is implement an IShapeTableProvider that describes the EditorTemplate shape and add an alternate based on the content type for example.

Sunday, May 17, 2015 8:04:11 PM bysfmskywalker

Re: Help with Shape Name

Just for infos, here my findings tested on a previous 1.x version: For the "Edit.cshtml", I think that you can't use a more specialized name because, here, the selected view is related to a controller action and depends on the razor view engine provider. So, the view is related to the area, controller and action names... It' only after, when Display(Model) is called, that you can use alternates at another level...

That said, if you want to work in an overridden "Edit.cshtml", one solution is to test the "Model.ContentItem.ContentType", and if equal to e.g "Image" then do your specific stuff...

If you want to work at a lower level, it would be better to use other alternates as: "Content.Edit.cshtml", "Content.Edit-Page", "Media.Edit.cshtml" for a media type, "Media.Edit-Image" for an image... But, infortunately, these alternates don't work in the current front end theme, only in "TheAdmin" theme.

But I've found one way to do that by using this in your "Edit.cshtml". Note that you don't need to test if your theme is the current one because this code is in the "Edit.cshtml" that is in your theme

  ....
  var contentType = Model.ContentItem.ContentType;
}
....
...
if (contentType == "Page") {
  Html.RenderPartial("~/themes/YourTheme/Views/Content.Edit-Page.cshtml", (object)Model);
}
else if (contentType == "Image") {
  Html.RenderPartial("~/themes/YourTheme/Views/Media.Edit-Image.cshtml", (object)Model);
}
else {
  @Display(Model)
}

Finally, at the next level, as Sipke said, you have the EditorTemplate for each part. But, fortunately, here it seems that you can use alternates in the current front end theme. E.g, I was able to use this alternate

/FrontEndTheme/Views/EditorTemplates/Parts.Media.Edit.cshtml

Best

Tuesday, May 19, 2015 1:33:35 AM byjtkech
  • jtkech
  • Lv. 13 Rookie
  • Total EXP: 1028

Post a reply

You need to be signed in to post a reply.

Sign In