The Now Platform® Washington DC release is live. Watch now!

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to apply CSS to knowledge articles?

filipwuyts
Mega Contributor

Hi,

I'm trying to apply a custom CSS to the articles in our Knowledge Base. As per the procedure explained in Uploading and referencing CSS, I've created a style sheet in Content Management > Design > Style Sheets. I then inserted the link to my style sheet at the top of the article:

<link href="sys_id_of_stylesheet_record.cssdbx" rel="stylesheet" type="text/css"></link>

However, upon saving the article, this line is stripped and replaced with

<p>  </p>

I found a procedure to insert the CSS link in every knowledge article (Custom CSS style sheets in non-CMS pages - ServiceNow Guru ), but sadly, that didn't work either.

My instance is on Geneva.

Any help much appreciated!

Thanks in advance,

Filip

1 ACCEPTED SOLUTION

Perhaps we should take a step back here and take a look at your requirements. Do you want the same style applied to all your KB Articles or are you looking at multiple styles?



I'm guessing you want to have a uniform look and feel for all your KB Articles. In which case what I'm giving you may be a bit overkill. What you could do is update the kb_view or kb_view_customer UI Pages, by adding a line such as this to the top:


<link href="stylesheet_sys_id.cssdbx" rel="stylesheet" type="text/css"></link>



In that ServiceNowGuru link, there's a question mark in the URL. You don't really need that. The above format should be good enough.



If you are hesitant in modifying the kb_view UI Page, there is a reference in the Wiki where customisations to this UI Page are preserved under a new UI Page called kb_view_customer when upgrading to Knowledge Management v3 (Migrating to Knowledge Management v3 - ServiceNow Wiki ). This may require some testing, but I'm wondering if this behaviour can be leveraged for you.



Unfortunately, what we are doing with Templates and Default values to "force" in styles are just hacks for HTML fields. If we could get near full-fledged support for WYSIWYG editing that would be absolutely lovely.



So, I would suggest you also raise an Enhancement Request on HI for styling support in HTML fields. If there's a lot of requests for this, it will certainly drum up interest with the ServiceNow Developers and, potentially, push them forward on this.


View solution in original post

8 REPLIES 8

Shahed Shah1
Tera Guru

Hi Filip



I've not had much experience with including stylesheets within the HTML text of a Knowledge Article, but the way I've included CSS is by actually coding in the style tag. So:


<style type="text/css"><!--


div.margin{


      padding: 10px 40px 40px 30px;


}


/*


* and so on ...


*/


--></style>



<div class="margin">


      <p class="title">Document Title</p>


      <p>Document content</p>


</div>



Then I revert back to the WYSIWYG editor and do the usual content creation there. To simplify this, so I do not have to do this every time, I then set the default values for a particular Knowledge Base to use this styling when a new article is created. (Reference: Administering Knowledge - ServiceNow Wiki ). There's more ideas here to set default values.



I hope that this helps you with your requirements.



EDIT: Correcting the ideas link


Hi Shahid,



Your answer and the links you provided pointed me in the right direction. I added a template kb_knowledge (in System Definition > Templates), so that every new KB article uses this template. The template itself contains the complete CSS within the article's HTML (Text field), as I cannot get ServiceNow to use an external CSS.



Although I prefer to have a link to an external CSS, this solution seems to work. However... meanwhile the user for which I am looking into this problem pointed out to me that manual operations in the Text field of a knowledge article (e.g. when drafting an article) can possible wipe out the entire HTML code:



  1. Create a new knowledge article
  2. The kb_knowledge template is invoked and the CSS code is added
  3. Start typing in the Text field
  4. Then delete all you have typed
  5. When you check in the source code editor (<>) you find that it is empty and all of the HTML code, including the CSS, is gone


I guess the only way to guarantee that CSS is invoked an applied would be to:



  1. Set up up the CSS
  2. Set up scripting on the kb article (onSubmit and/or onCellEdit?) to check if the CSS info is still there and if not, re-insert it


Unfortunately my knowledge of scripting is too limited for this 🙂



Filip


That is strange. I'm wondering if the deletion of the text to the start makes the TinyMCE editor remove all the content and replaces it with some tags of it's own. Scripting this is going to be quite a lot of work. I will have to do some testing.



In the meantime, if you need to get something going soon, you could hide the Text field and create another html field for the text only side. Then on submit you can merge whatever styling you want (stored in another table?) and merge the styling with the text into the Text field using a BR?



- Shahid


I can actually reproduce this behaviour on an OOB instance and this seems to have an effect on all the HTML fields. In all honesty I have never done such testing before. I wonder if we should log a Problem for this.