SOLVED

Code snippet web part

Copper Contributor

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:

CodeSnippet.PNG

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

 

Greetings from Denmark

 

/Frank

9 Replies

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.

best response confirmed by Frank Nielsen (Copper Contributor)
Solution

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. 

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

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

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. 

Probably not, Microsoft do not want people to be making code changes to sites as they will inevitably break when a future update comes along (which seems to happen every other day at the moment).

Rob
Los Gallardos

Hi Rob. I can see it from there point of view. I have earlier worked in a software company that had a very open product, so the customers could make a lot of local changes. But every time we made an upgrade of the product, the customers got a lot of errors in their custom solutions. And we were the one to blaime :\

 

Frank

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 

@Amanda DowningThe main problem for me is, that after publishing the code via the code snippet web part, it cannot be copied (Strg+C) from the sharepoint site. For the browser is looks like a picture.
Does someone have a solution for this?

1 best response

Accepted Solutions
best response confirmed by Frank Nielsen (Copper Contributor)
Solution

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. 

View solution in original post