Knowledge Base

Adding Code Snippets

Article ID: 411
Last updated: 20 Jun, 2019

You may want to add code examples, or snippets, to your knowledgebase article to show your users how to achieve a particular effect or address a common problem. KBPublisher makes this easy by providing formatting tags to put around the example. When your readers look at the article, the example code appears, correctly formatted for the coding language you specify, and highlighted as it would appear in a code editor for that language, in a box to set it off from the rest of the text.

There are two options to add code snippet to an article.

Option 1 - toolbar button

To add code snippets to an article by using the toolbar button:

  1. Open the article for editing.
  2. Place cursor where you want the code snippet to appear. (You can move the snippet later, if needed.)
  3. Click the "Insert Code Snippet" icon in the editor toolbar .
  4. In the Code snippet window, select a language and add your code content.
  5. Click OK.

Example:

<?php 
$value = 'something from somewhere';
setcookie("TestCookie", $value);
setcookie("TestCookie", $value, time()+3600);  /* expire in 1 hour */
setcookie("TestCookie", $value, time()+3600, "/~rasmus/", "example.com", 1);
?>

Available Languages

In the Language drop down menu, the following options are available:

  • Apache
  • Bash
  • CoffeeScript
  • C++
  • C#
  • CSS
  • Diff
  • HTML
  • HTTP
  • INI
  • Java
  • JavaScript
  • JSON
  • Makefile
  • Markdown
  • Nginx
  • Objective-C
  • Perl
  • PHP
  • Python
  • Ruby
  • SQL
  • VBScript
  • XHTML
  • XML

Option 2 - [code] tag

To add code snippets to an article by using the [code] tag:

  1. Open the article for editing.
  2. Add opening and closing tags around your code snippet:
    [code=XXX] Add your code here. [/code]
  3. Replace the XXX with the indicator from the list below for the snippet's coding language.
  4. Paste your code between the opening and closing tags.
  5. Preview the article to confirm it appears as you want.

Example:

<?php 
$value = 'something from somewhere';
setcookie("TestCookie", $value);
setcookie("TestCookie", $value, time()+3600);  /* expire in 1 hour */
setcookie("TestCookie", $value, time()+3600, "/~rasmus/", "example.com", 1);
?>

Available Languages

Find your snippet's coding language on the left side of any pair. Choose one of the entries that appear on the right side. For AS3, for example, you could use "code=as3" or "code=actionscript3".

Code Language Indicator
AS3
  • actionscript3
  • as3
Bash
  • bash
  • shell
CSharp
  • c-sharp
  • csharp
ColdFusion
  • cf
  • coldfusion
Cpp
  • c
  • cpp
Css
  • css
Delphi
  • delphi
  • pas
  • pascal
Diff
  • diff
  • patch
Erlang
  • erl
  • erlang
Groovy
  • groovy
JScript
  • javascript
  • js
  • jscript
Java
  • java
JavaFX
  • javafx
  • jfx
Perl
  • perl
  • pl
Php
  • php
Plain
  • plain
  • text
PowerShell
  • powershell
  • ps
Python
  • py
  • python
Ruby
  • rails
  • ror
  • ruby
Scala
  • scala
Sql
  • sql
Vb
  • vb
  • vbnet
Xml
  • html
  • xhtml
  • xml
  • xslt
Article ID: 411
Last updated: 20 Jun, 2019
Revision: 3
Access: Public
Views: 3562
Comments: 0