PerplexDigital / Perplex.ContentBlocks

Block based content editor for Umbraco
MIT License
31 stars 15 forks source link

Add content programatically? #48

Closed AndersBrohus closed 3 years ago

AndersBrohus commented 3 years ago

Hi :)

Is it possible to add content programatically? Currently have an old website with alot of older nodes which has to be imported and if possible setup using one block of the blocks that are available :)

PerplexDaniel commented 3 years ago

Technically, sure. There are no APIs in our package to create blocks, but you can use Umbraco's IContentService and use SetValue() to set a ContentBlocks property value yourself. The structure is something like this. Main thing is generating that "Nested Content data" part of the JSON somehow.


{
  "version": 2,
  "header": {
    "id": "...",
    "definitionId": "...",
    "layoutId": "...",
    "presetId": null,
    "isDisabled": false,
    "content": [{ /* Nested Content data */ }]
  },

  "blocks": [
    /* Same format as header */
  ]
}
AndersBrohus commented 3 years ago

Arh okay, thanks alot :)

Will try and see how i can do that :)

Should we change the issue to just insert this in the "documentation"? :)

PerplexDaniel commented 3 years ago

Added a section about this to the readme.