4
votes

In the module for 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 =>
               table.ContentPartRecord()
                    .Column<string>("Html"));                                                      
            return 2;
        }

So, I have a column called Html. I want to use the WYSIWYG editor, so I am told I need a Text field to get this to work "out of the box".

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

And how do I configure it to use the WYSIWYG editor?

2

2 Answers

8
votes

If you want a property of your own custom contentpart to be displayed as a htmleditor, configure it as follows in the editortemplate of your part.

@Script.Require("OrchardTinyMce")
@Html.TextAreaFor(x => x.Header, new { @class = "html tinymce" }) 

In this case the 'Header' property is displayed as a html editor.

If you need this in more parts you can consider writing a Html extension or editor template for it.

5
votes

A text field is not the same thing as a part property. Fields are not stored as their own database column. Here is an example of how you add a field to a part from a migration:

        ContentDefinitionManager.AlterPartDefinition("Product",
          builder => builder.WithField("ProductImage", fieldBuilder => fieldBuilder.OfType("MediaPickerField").WithDisplayName("Product Image")));

For text field, you'd also need to set the flavor setting by adding .WithSetting("Flavor", "html") to the field builder.