Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ryan Faurskov 3 posts 73 karma points
    Sep 24, 2021 @ 12:02
    Ryan Faurskov
    0

    appsettings.json - RichTextEditor - CustomConfig - templates

    Hi

    How to add templates in the RichTextEditor/CustomConfig section in appsettings.json?

    In v8 it was a array of objects but in v9 it's a key value pairs of strings.

    V8enter image description here

    V9 enter image description here

    Anyone else run into this and found a solution?

    //Ryan

  • Sebastiaan Janssen 5009 posts 15264 karma points MVP admin hq
    Sep 24, 2021 @ 13:26
    Sebastiaan Janssen
    0

    I haven't tried yet, but have you tried escaping it?

  • Ryan Faurskov 3 posts 73 karma points
    Sep 24, 2021 @ 13:40
    Ryan Faurskov
    0

    I tried this but it didn't work

    "CustomConfig": {
              "Templates" : "[{ \"title\": \"Infobox Blue\", \"description\": \"A box with highlighted background color\", \"url\": \"../App_Plugins/RTE/infobox-blue.html\" }]"
            },
    
  • Ryan Faurskov 3 posts 73 karma points
    Sep 24, 2021 @ 13:43
    Ryan Faurskov
    104

    Ahh templates with lowercase =)

    Thx

    "CustomConfig": {
          "templates" : "[{ \"title\": \"Infobox Blue\", \"description\": \"A box with highlighted background color\", \"url\": \"../App_Plugins/RTE/infobox-blue.html\" }]"
        },
    
  • Joe Harvey 22 posts 122 karma points
    Aug 08, 2022 @ 10:23
    Joe Harvey
    0

    I was struggling to work out how to implement something similar for style_formats in Umbraco v9 and v10 etc, which in v8 tinyMceConfig.config XML was as below:

    <customConfig>
        <config key="style_formats">
        [
          {
              "title": "Common",
              "items": [
                  {
                      "title": "Paragraph",
                      "block": "p"
                  }
              ]
          }
        ]
      </config>
    </customConfig>
    

    I tried the seemingly logical approach of putting that JSON directly in the new appsettings.json' e.g.:

    "RichTextEditor": {
        "CustomConfig": {
          "style_formats":  [
          {
              "title": "Common",
              "items": [
                  {
                      "title": "Paragraph",
                      "block": "p"
                  }
              ]
          }
        ]
      }
    }
    

    However, that threw:

    An error occurred Cannot create instance of type 'System.String' because it is missing a public parameterless constructor.

    with references to Umbraco.Cms.Web.BackOffice.PropertyEditors.RichTextPreValueController.GetConfiguration() and Umbraco.Cms.Core.Models.ContentEditing.RichTextEditorConfiguration which, having inspected the v10 core code, I can see only accepts a dictioanary of strings for CustomConfig:

    [DataMember(Name = "customConfig")]
    public IDictionary<string,string>? CustomConfig { get; set; } 
    

    I then found this article and can confirm that the suggestion of escaping the JSON works in the case of style_formats too, e.g.:

      "RichTextEditor": {
        "CustomConfig": {
          "style_formats": "[{\"title\": \"Images\",\"items\": [{\"title\": \"Image Left\",\"selector\": \"img\",\"classes\": \"image-left\"},{\"title\": \"Image Centre\",\"selector\": \"img\",\"classes\": \"image-centre\"},{\"title\": \"Image Right\",\"selector\": \"img\",\"classes\": \"image-right\"}]}]"
        }
      }
    

    This seems like absolute madness to me?

    Have we seriously made the jump form XML based config files in v8 (with embedded JSON within the XML data) to JSON based config files in v9+, only to require difficult to form/read/update, single-line, encoded JSON for some settings? Surely the entire CustomConfig section could just allow for freeform JSON which is then parsed into Umbraco.Cms.Core.Models.ContentEditing.RichTextEditorConfiguration and any unrecognised keys and/or settings discarded?

  • Huw Reddick 725 posts 2413 karma points
    4 days ago
    Huw Reddick
    0

    I have now set mine up to do this automatically, some instructions and code in the link below

    https://umbraco.themediawizards.co.uk/the-grimoire/formatting-for-richtexteditor-config/

Please Sign in or register to post replies

Write your reply to:

Draft