Copied to clipboard

Flag this post as spam?

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


  • Dan Patching 31 posts 158 karma points c-trib
    Jan 06, 2016 @ 14:36
    Dan Patching
    0

    Populate grid layout with IContent.SetValue

    Hi all,

    I'm trying to import some html into a grid layout programmatically. The grid just needs to be 1 column, 1 row, with a rich text editor to hold the html.

    I've tried rendering an existing grid in JSON, to get the structure, replace the html, and then use SetValue on IContent, but the resulting grid is empty in the back office.

    The same question is on Stackoverflow, but there's no answer.

    How would you import content into Umbraco page Grid Layout using ContentService?

    Has anyone successfully done this, or have any idea where i'm going wrong?

    Thanks in advance for any help!

    Dan

  • Dan Patching 31 posts 158 karma points c-trib
    Jan 06, 2016 @ 15:46
    Dan Patching
    3

    It turned out my issue was that I had quotes in the html that needed escaping, so it was breaking the JSON.

    SetValue with the JSON below worked for me.

              String gridContent = @"{
              ""name"": ""1 column layout"",
              ""sections"": [
                {
                  ""grid"": 12,
                  ""rows"": [
                    {
                      ""name"": ""Headline"",
                      ""areas"": [
                        {
                          ""grid"": 12,
                          ""controls"": [
                            {
                              ""value"": """ + escapedQuotes + @""",
                              ""editor"": {
                                ""alias"": ""rte""
                              }
                            }
                          ]
                        }
                      ],
                      ""id"": ""9feb0fd9-513d-9a92-6d15-c78c242a3cf2""
                    }
                  ]
                }
              ]
            }";
    
  • Gopi Bekkanti 3 posts 72 karma points
    Oct 21, 2017 @ 06:10
    Gopi Bekkanti
    0

    Hi Dan Patching,

    Thanks for the above snippet.

    I want one clarification from that. I am thinking that the variable string gridContent is Property Group. please clarify me If I was wrong.

    Thanks in Advance,

    Gopi B.

Please Sign in or register to post replies

Write your reply to:

Draft