|
| 1 | +# Rich Text Editor TinyMce |
| 2 | + |
| 3 | +`Schema Alias: Umbraco.RichText` |
| 4 | +`UI Alias: Umb.PropertyEditorUi.TinyMCE` |
| 5 | + |
| 6 | +`Returns: HTML` |
| 7 | + |
| 8 | +{% hint style="warning" %} |
| 9 | +This article is a work in progress and may undergo further revisions, updates, or amendments. The information contained herein is subject to change without notice. |
| 10 | +{% endhint %} |
| 11 | + |
| 12 | +The Rich Text Editor (RTE) is highly configurable and based on [TinyMCE](https://www.tinymce.com/). Depending on the configuration, it will give your content editors more flexibility when working with content that should be more than plain text. |
| 13 | + |
| 14 | +{% hint style="info" %} |
| 15 | +**Are you using custom configurations or plugins with TinyMCE?** |
| 16 | + |
| 17 | +In Umbraco 11 the TinyMCE version supported has been upgraded from version 4 to version 6. You need to migrate to the latest version if you are using TinyMCE plugins or custom configuration. |
| 18 | + |
| 19 | +If your site is upgraded from an older version, follow the migration guides below to upgrade the TinyMCE version as well. |
| 20 | + |
| 21 | +* [Migrate from version 4 to version 5](https://www.tiny.cloud/docs/tinymce/5/migration-from-4x/) |
| 22 | +* [Migrate from version 5 to version 6](https://www.tiny.cloud/docs/tinymce/6/migration-from-5x/) |
| 23 | +{% endhint %} |
| 24 | + |
| 25 | +## [Configuration options](configuration.md) |
| 26 | + |
| 27 | +Customize everything from toolbar options to editor size to where pasted images are saved. |
| 28 | + |
| 29 | +## [Styles](styles.md) |
| 30 | + |
| 31 | +Use CSS to define specific editor styles and add them as formatting options of the Rich Text Editor. |
| 32 | + |
| 33 | +## [Blocks](blocks.md) |
| 34 | + |
| 35 | +Use Blocks to define specific parts that can be added as part of the markup of the Rich Text Editor. |
| 36 | + |
| 37 | +## [Plugins](plugins.md) |
| 38 | + |
| 39 | +Extend the functionality of the Rich Text Editor with plugins. |
| 40 | + |
| 41 | +## Data Type Definition Example |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | +## Content Example |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | +## MVC View Example |
| 50 | + |
| 51 | +### Without Modelsbuilder |
| 52 | + |
| 53 | +```csharp |
| 54 | +@{ |
| 55 | + if (Model.HasValue("richText")){ |
| 56 | + <p>@(Model.Value("richText"))</p> |
| 57 | + } |
| 58 | +} |
| 59 | +``` |
| 60 | + |
| 61 | +### With Modelsbuilder |
| 62 | + |
| 63 | +```csharp |
| 64 | +@{ |
| 65 | + if (!string.IsNullOrEmpty(Model.RichText.ToString())) |
| 66 | + { |
| 67 | + <p>@Model.RichText</p> |
| 68 | + } |
| 69 | +} |
| 70 | +``` |
| 71 | + |
| 72 | +## Add values programmatically |
| 73 | + |
| 74 | +See the example below to see how a value can be added or changed programmatically. To update a value of a property editor you need the [Content Service](https://apidocs.umbraco.com/v15/csharp/api/Umbraco.Cms.Core.Services.ContentService.html). |
| 75 | + |
| 76 | +{% hint style="info" %} |
| 77 | +The example below demonstrates how to add values programmatically using a Razor view. However, this is used for illustrative purposes only and is not the recommended method for production environments. |
| 78 | +{% endhint %} |
| 79 | + |
| 80 | +```csharp |
| 81 | +@using Umbraco.Cms.Core.Services; |
| 82 | +@inject IContentService Services; |
| 83 | +@{ |
| 84 | + // Get access to ContentService |
| 85 | + var contentService = Services; |
| 86 | + |
| 87 | + // Create a variable for the GUID of the page you want to update |
| 88 | + var guid = Guid.Parse("32e60db4-1283-4caa-9645-f2153f9888ef"); |
| 89 | + |
| 90 | + // Get the page using the GUID you've defined |
| 91 | + var content = contentService.GetById(guid); // ID of your page |
| 92 | +
|
| 93 | + // Create a variable for the desired value |
| 94 | + var htmlValue = new HtmlString("Add some text <strong>here</strong>"); |
| 95 | + |
| 96 | + // Set the value of the property with alias 'richText'. |
| 97 | + content.SetValue("richText", htmlValue); |
| 98 | + |
| 99 | + // Save the change |
| 100 | + contentService.Save(content); |
| 101 | +} |
| 102 | +``` |
| 103 | + |
| 104 | +Although the use of a GUID is preferable, you can also use the numeric ID to get the page: |
| 105 | + |
| 106 | +```csharp |
| 107 | +@{ |
| 108 | + // Get the page using it's id |
| 109 | + var content = contentService.GetById(1234); |
| 110 | +} |
| 111 | +``` |
| 112 | + |
| 113 | +If Modelsbuilder is enabled you can get the alias of the desired property without using a magic string. |
| 114 | + |
| 115 | +{% hint style="warning" %} |
| 116 | +The following example uses `IPublishedSnapshotAccessor` which is obsolete in Umbraco 15 and will be removed in a later version. |
| 117 | +{% endhint %} |
| 118 | + |
| 119 | +```csharp |
| 120 | +@using Umbraco.Cms.Core.PublishedCache; |
| 121 | +@inject IPublishedSnapshotAccessor _publishedSnapshotAccessor; |
| 122 | +@{ |
| 123 | + // Set the value of the property with alias 'richText' |
| 124 | + content.SetValue(Home.GetModelPropertyType(_publishedSnapshotAccessor, x => x.RichText).Alias, "Add some text <strong>here</strong>"); |
| 125 | +} |
| 126 | +``` |
0 commit comments