Forum Discussion

Frank Nielsen's avatar
Frank Nielsen
Copper Contributor
Feb 06, 2019
Solved

Code snippet web part

Hi SharePoint gurus.

I have a SharePoint Modern page where I want to hide the header of a web part. I have taken out the ID of the header and used the code snippet web part, but the header is still visible. Also the code snippet web part is visible. I thought that the web part only would be visible when editing the page? Please look below:

Forgive Me for My poor code abilities, but I am very new to this kind of working wtih SharePoint.

 

Greetings from Denmark

 

/Frank

  • As others have mentioned, the code snippet web  part just displays code, it doesn't execute it.

    You should also be aware that trying to override out of the box styles is not good practice. Those IDs are subject to change and they will  change as they are dynamically generated. 

9 Replies

  • As others have mentioned, the code snippet web  part just displays code, it doesn't execute it.

    You should also be aware that trying to override out of the box styles is not good practice. Those IDs are subject to change and they will  change as they are dynamically generated. 

    • JMU Cloud Share's avatar
      JMU Cloud Share
      Copper Contributor

      Will the code snippet web part actually work at some point?  I don't see any purpose for a non working code snippet web part. 

      • Amanda Downing's avatar
        Amanda Downing
        Brass Contributor

        From my perspective the Code Snippet web part does work. It allows you to share pieces of code. It isn't meant to act as a window to run code, but a means of sharing pieces of code in a visual manner. 

        JMU Cloud Share 

    • Frank Nielsen's avatar
      Frank Nielsen
      Copper Contributor

      Thank you so much for quick reply. Last night i did find a script editor webpart for modern pages on GitHub, and will take a look at that instead. It is not some great changes I want to make, so I will give it a try.

       

      https://github.com/SharePoint/sp-dev-fx-webparts/tree/master/samples/react-script-editor

       

      Frank

    • Frank Nielsen's avatar
      Frank Nielsen
      Copper Contributor

      Thank you so much for quick reply. Last night i did find a script editor webpart for modern pages on GitHub, and will take a look at that instead. It is not some great changes I want to make, so I will give it a try.

       

      https://github.com/SharePoint/sp-dev-fx-webparts/tree/master/samples/react-script-editor

       

      Frank

  • Robin Nilsson's avatar
    Robin Nilsson
    Bronze Contributor

    The code snippet webpart doesn't do anything - the code is not executed. It's only used to display code so you can use it to document programs and such. There is not a way currently to add code to a modern page.

Resources