Adding a Text Field to Custom ContentPart

Topics: Customizing Orchard, Writing modules
May 31, 2012 at 11:16 AM
Edited May 31, 2012 at 2:04 PM

In the module where I define a custom ContentPart, how do I set a field to be a Text field?

In my migrations.cs class, I have created the table for the part:


public int UpdateFrom1()
            SchemaBuilder.CreateTable("RightContentPartRecord", table =>
            return 2;

So I have one column<string> called Html.  I want to use the WYSIWYG editor in the dashboard to add/edit content for this field, so I am told I need a "Text field" for this to work "out of the box".

However, this isn't happening for me, so I am missing something.  What do I need to do to turn my column called Html into a Text field on the part?

May 31, 2012 at 3:26 PM

OK, so I have found how to add a text field to my part:

public int UpdateFrom3()
                typeof(RightContentPart).Name, builder => builder
                    .WithField("ImATextField", f => f.OfType(typeof(TextField).Name)));
            return 4;

However, this adds ImATextField as a Content Field, which is equivalent to adding the field in the Dashboard.

The problem I have with that is that the ImATextField field is not part of the model of the part.  Ie, it is not part of the part shape.

The problem with that is that I want to place the shape using @randompete 's ZoneProxy code.  So as the ImATextField is not part of the Parts_MyPart shape, I can't place it, as its shape is a Fields_Common_Text shape.  So if I place that, I will be placing ALL the other Fields_Common_Text shapes, that I want to place elsewhere.

So, I really, really need my field to be part of my Part's shape.  

To get that, I need it to be part of my model.  To get that, I can't use a Content Field in my module's migrations.cs class, because it will have a generic shape name such as Fields_Common_Text that I have no control over.

Any pointers?  Are the statements in the above paragraph correct?

May 31, 2012 at 6:00 PM

No, those statements are not correct. You can use placement on a specific field."Place"Element