Copied to clipboard

Flag this post as spam?

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


  • von 61 posts 123 karma points
    Mar 24, 2017 @ 08:38
    von
    0

    Setting Grid value in code

    Hello,

    What is the correct of way of setting a grid value in code? If I set a grid's value with a properly formatted json data, it will save without errors using ApplicationContext.Services.ContentService.SaveAndPublishWithStatus. But once the content is loaded in the back-office the value is not showing up.

    I checked the database and the cmscontentxml has the correct value as well. The umbraco.config contains the correct value as well. Even after republishing the entire site, stop and started the service, the grid is empty.

    This is the content of the grid in umbraco.config

    <grid><![CDATA[{
      "name": "1 column layout",
      "sections": [
        {
          "grid": 12,
          "rows": [
            {
              "label": "1 Column",
              "name": "1 Column",
              "areas": [
                {
                  "grid": 12,
                  "hasConfig": false,
                  "controls": [
                    {
                      "value": "<p>This is a test</p>",
                      "editor": {
                        "alias": "rte"
                      },
                      "active": true
                    }
                  ],
                  "active": true
                }
              ],
              "hasConfig": false,
              "id": "2d69bae5-9cdd-7dbb-3efe-869fbcd89491",
              "hasActiveChild": true,
              "active": true
            }
          ]
        }
      ]
    }]]></grid> 
    
  • Kevin Jump 2309 posts 14673 karma points MVP 7x c-trib
    Mar 24, 2017 @ 18:03
    Kevin Jump
    0

    Hi,

    yeah setting grid values is a real pain - there doesn't appear to be any objects you can deserialize too :(

    however when i do something similar the only difference i can see is that i have an allowed section in the json - and depending on how umbraco loads the grid that might matter ?

        <content><![CDATA[{
      "name": "1 column layout",
      "sections": [
        {
          "grid": 12,
          "rows": [
            {
              "name": "Full Width",
              "areas": [
                {
                  "grid": 12,
                  "allowAll": false,
                  "allowed": [
                    "rte",
                    "media",
                    "macro",
                    "embed"
                  ],
                  "hasConfig": false,
                  "controls": [
                    {
                      "value": "<p style=\"text-align: left;\">some content</p>",
                      "editor": {
                        "alias": "rte"
                      },
                      "active": true
                    }
                  ],
                  "active": true,
                  "hasActiveChild": true
                }
              ],
              "hasConfig": false,
              "id": "f0882451-03bd-dc64-f58d-253d9cf2f18d",
              "active": true,
              "hasActiveChild": true
            }
          ]
        }
      ]
    }]]></content>
    
Please Sign in or register to post replies

Write your reply to:

Draft