This project is read-only.

Override default Content.ControlWrapper.cshtml for items in custom module

Nov 12, 2010 at 4:37 PM


I've devloped my own module (content type). In my module I display list of items wich use Content.ControlWrapper.cshtml from core.

The menu for each item contains only edit action. I've copied Content.ControlWrapper.cshtml file to my module to root of views folder and i've added another action to menu.

But here is the problem. All modules and parts with items then use this copied cshtml.


1. How can I override Content.ControlWrapper.cshtml only for my module (content type). It is possible?

2. How can I add another action to item menu ?

Nov 16, 2010 at 1:06 AM

1. By overriding Content.ControlWrapper.cshtml, you're overriding a whole stereotype, not just one shape. Instead, override the specific shape template you need.

2. Which menu? Front end or admin?

Nov 16, 2010 at 6:00 AM

1. I want to override Content.ControlWrapper.cshtml but not for whole site. I want to use overriden Content.ControlWrapper.cshtml only in my module when displaying my module content type and not in any other module. If I copy and override Content.ControlWrapper.cshtml in my root view module folder, then it is used by whole site not only in my module. Is there another way to specify which base shape will be used for items rendering (other than Content.ControlWrapper.cshtml) only in my module scope when rendering my module content types?

2. Front end menu. It is possible to add another action in item menu. I see only Edit action (which is included in Content.ControlWrapper.cshtml), but I want to add Remove action too. 

Nov 16, 2010 at 6:11 AM

Again, Content.ControlWrapper is way too wide. That's not what you want to override, you want to only override the rendering of the shape for your content type. That will take care of the scoping. Unless I'm missing something in which case you should give more details about what excatly you're trying to chieve.

For the menu, you can look at the Widget.ControlWrapper.cshtml template for an example. You should be able to create a similar menu for your own shapes.

Nov 16, 2010 at 2:34 PM

I will try to explain once again my whole problem.

I want to use List shape (using New.List) with my own content type (own content part) and a custom menu (not only Edit item). This is what I want to achive.

So, I have already created my own content part and content type, I've already created service which return me list of my content types (including my part) and I  I have already display it with List shape. But here is the problem. Default list shape has only Edit menu item. I want to add one more item in menu but I don't know how. I thought that I can override Widget.ControlWrapper.cshtml in my module and add another menu. But this way I'am overriding whole stereotype, just you said. One solution that I remember is to make my own List shape an logic of rendering all of the parts of my content type.

But I want to know is there any better solution to reuse existing List shape and its logic with some changes (with menu item added). And this changes must exists only when I rendering list of my content type. Rendering other content types which also use List shape must be the same as before.

Nov 16, 2010 at 7:37 PM
Edited Nov 16, 2010 at 7:37 PM

Thanks for the explanation. If I may ask just one more question: do you want that menu to appear for each item in the list or once for the whole list?

Nov 16, 2010 at 8:51 PM

Thanks for your  fast reply. For now, I want the menu to appear for each item, just like implemented existing menu which has edit item. All I want is to add one more menu item with reusing existing List shape. Maybe some
other time I will need global menu too, so if you write some information about implementing it it will be usefull too.

Nov 16, 2010 at 11:39 PM

In that case you do not need to override the list rendering, just the summary rendering for that specific content type. This can be done with a wrapper as you just want to decorate it from the module code. I think something like this should work:

public class Shapes : IShapeTableProvider {
    public void Discover(ShapeTableBuilder builder) {
            .OnDisplaying(displaying =>
                if (displaying.Shape.ContentItem.ContentType == "YourContentTypeName") {

And then in views, just add a YourContentTypeName.Wrapper.cshtml file where you define your menu.

Nov 17, 2010 at 7:54 AM
Edited Nov 17, 2010 at 1:37 PM

It works when I am using builder.Describe("Content") and not if i'am using builder.Describe("Content_Summary") like you wrote.

In my controller I make list item shape by using  _services.ContentManager.BuildDisplay(b,"Summary").

If I am using builder.Describe("Content_Summary"), OnDisplaying event doesn't trigger.

Another problem is that my wrapper and default wrraper, both are rendered for each list item. If I add my wrapper on OnDisplaying in my IShapeTableProvider, the default Content.ControlWrapper.cshtml is still added in default shape table provider. Both wrapper then will be rendered. I want to render only my wrapper.



Nov 18, 2010 at 7:57 AM
Edited Nov 18, 2010 at 8:00 AM

From my last post, I want to know 2 answers:

1. Why IShapeTableProvider doesn't trigger with Content_Summary shape or am I doing something wrong?

2. How to change default Content.ControlWrapper.cshtml with my wrapper only (not to render default wrapper too)?

Please could anyone help me.

Nov 18, 2010 at 8:02 AM

Don't name your shape "summary", name it something specific. If you want to suppress the existing wrapper, just do that and clear the collection of wrappers before you add to it. If you had named your shape something specific, you could override just that instead of overriding content.

Nov 18, 2010 at 9:33 AM

Yes, yes, yes :) Thanks.