Overriding Core Content.Edit shape template

Topics: Customizing Orchard, Writing themes
May 13, 2011 at 3:56 AM

  I'm trying to override the standard Content.Edit.cshtml template so that I can hide the permalink markup and add a few widgets of my own for a particular content type.  I have Url Alternates turned on and I used Shape Tracing to create a custom edit template.  The template was created successfully in my project but the new template is not being used to override the original template.  According to shape tracing, the Active Template is still ~/Core/Contents/Views/Content.Edit.cshtml. Am I missing something?  Do I need to override the Editor method in a content driver or something? Thanks.


May 13, 2011 at 4:02 AM

You can't override admin templates unless you also build a theme selector that gives your theme a higher priority than the built-in one. But in any case, overriding content.edit.cshtml looks like a very bad idea. It seems like what you need to change is placement, in order to send the routable part to "-". On the other hand, one has to wonder: if you don't want that part, why don't you just remove it from the content type?

Also, I'm not sure what you mean by widget in this context. Do you mean parts?

May 13, 2011 at 4:13 AM

  Thanks for the response.  I'm still trying to wrap my head around shape customizations.  I still want the part to be routable. I just want to strip the end user of the power to dictate what the url should be.  So, would I be correct in assuming the part should still be a part of the content type in this case?

May 13, 2011 at 4:20 AM

So how is the route determined then? You might need to replace the part with your own.

May 13, 2011 at 4:20 AM

  Also, regarding the Placement.info, here's what I have:

   <Match ContentType="MyTestType">
    <Place Parts_Routable_Edit="-" />
    <Place Parts_RoutableTitle_Summary="Content:after.9"/>


What I really want is to keep the Title but remove the "Permalink" part.  However, by hiding Place Parts_Routable_Edit, I lose both.  How should a placement.info file look if I want to retain the title but hide the permalink?

May 13, 2011 at 4:22 AM

The route will be determined exactly the way it is out of the box.  I just don't want to have the end user worrying about specifying url's.

May 13, 2011 at 4:24 AM

I'm afraid you'll have to implement a theme selector or implement your own replacement for the routable part then.

May 13, 2011 at 4:28 AM

Ok I'll investigate writing a new routable part all together.  What exactly do you mean by a theme selector?

May 13, 2011 at 4:29 AM

This: http://weblogs.asp.net/bleroy/archive/2011/02/27/dynamically-switching-the-theme-in-orchard.aspx

May 13, 2011 at 9:18 AM
Edited May 13, 2011 at 9:19 AM

Can't you just override Parts_Routable_Edit? (I mean in a module, not in your theme)

May 13, 2011 at 5:10 PM

No, you can't reliably override templates in modules, only define them. And as the admin theme has a priority of 100, no theme can override it except if it sets itself at an even higher priority.

May 15, 2011 at 8:55 PM

  Hi. I'm a little curious about the suggestion to create a custom route content part.  Should this really be a content part or a widget?  How do you typically distinguish between the two?

May 15, 2011 at 9:04 PM

The reason I ask is because I don't want a new table to persist routes.  I still want to persist to the Routable_RoutePartRecord table.  I just don't want the Permalink html to be rendered for users to specify their own url.

May 16, 2011 at 11:38 AM

1. Let me explain what they are. A widget is just a special type of content item. Like any other content item, it is made up of various parts that define it. Widgets are then displayed in zones around the page, according to various rules (layers). So widgets are for a specific purpose, whereas parts are general purpose components used to build up functionality in items or widgets. How implementing routing in a widget would help in any way is beyond me!

Orchard's built-in routing is implemented as a part (RoutePart) that when attached to content items allows them to have a "friendly URL" route on which they can be viewed. This is just a "default" provision of routing. For a counter example, look at this thread: http://orchard.codeplex.com/discussions/255829 - smeyers builds a RoutableByDatePart which can be used for yyyy/mm/dd style routes for calendars, blogs etc.

So what I'm getting at is, why don't you want a new table? There's nothing "special" about the Routable_RoutePartRecord table, it's just the backing store for a plain ol' content part.

However you can probably get away with writing your own RoutePartDriver and emitting a custom shape with your own template, then hiding the ordinary routepart editor using Placement. I think routepart automatically slugifies the title when it publishes anyway. But if you hit any difficulties with that, you should probably just build your own part anyway.

May 17, 2011 at 1:00 AM

 Thanks for the reply, randompete.  I understand what you're saying about the conceptual difference between widgets and parts.  I'm not necessarily against adding a new table to store routes.  It just seemed like overkill for what I'm trying to do.  I'll try the RoutePartDriver idea with a custom shape. Thanks again.