Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Orchard CMS 1.4: Adding a Text Field to Custom ContentPart

Tags:

orchardcms

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?

like image 780
awrigley Avatar asked Dec 13 '22 01:12

awrigley


2 Answers

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.

like image 92
Mark Z Avatar answered Dec 31 '22 06:12

Mark Z


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.

like image 36
Bertrand Le Roy Avatar answered Dec 31 '22 08:12

Bertrand Le Roy