Documentation

Pseudo Code for other Server-Side Technologies

Please contact us if you have other server-side code requests we have not yet gotten around to putting up. We are happy to help.

The General Concept is you are making an HTTP request to a CDN resource to pull content but in a very specific way to work with KitGUi. View the PHP example to get a better idea of how KitGUI is being pulled.

Each instruction line assumes a new "block" of code and should not be lumped within the same condition.

Pseudo Code for your server-side for non-cached version

  1. Its important to have the end result to be something you can simply call directly on the page in a single line for usability for example in the PHP code sample you can do the following:
    <?php echo KitGUI::getContent("your-content-id","HTML"); ?> which is extremely terse and convenient to use multiple times on a page.

  2. Make a method returning a string. Call the method KitGUI_Get_Content or KitGUI.GetContent or similar in your preferred style, it doesn't matter the name of the method as long as its easy for you to understand. It is more convenient for it to be static without having to be instantiated if possible to do it this way in your preferred language. In the PHP example, its using a static class that has the "getContent" method within it for ease of use for example.

  3. Your method should have at least two parameters  (1) a string for the content ID and (2) a string for the content type. A possible third parameter (3) could be the account key or you can have that as a configuration item or hard code it within.
     
  4. You must ensure your content ID starts with a letter and follows with a series of any one of these: letters, numbers, underscores or dashes. If not, throw an exception as you should not proceed because the ID would be incompatible with KitGUI. The PHP example has a regular expression as well as the .NET example for your review.
     
  5. Within your method, declare a URL string variable instantiated with the following string:  "http://s3.amazonaws.com/kitgui/clients/" + [your account key] + "/ids/" + [your content ID] + ".txt"
     
  6. Witin your method, declare a string variable for your HTML response.
     
  7. Within your method, make an HTTP Request with that URL and trap a 404 error or 404 header response and assign empty string to the HTML variable if 404 or error. If not error, assign the file contents back to the HTML variable.
     
  8. Within your method, declare a boolean variable for indicating the page is in edit mode or not. Check for the existence of a cookie defined as "kitgui" that has the value "1". If that condition is met, set the edit mode variable to true, otherwise false.
     
  9. If edit mode is true, return a string from your method in the following format :
    "<div style=\"display:inline-block\" class=\"kitgui-id-\"| + [your content ID] + " " + "kitgui-content-type-" + [your content type] + "\">" .+ [Your HTML variable contents] + "</div>"
    else, if its not in edit mode then simply return the contents of the HTML variable

 

Pseudo Code for your server-side for cached version

  1. Its important to have the end result to be something you can simply call directly on the page in a single line for usability for example in the PHP code sample you can do the following:
    <?php echo KitGUI::getContent("your-content-id","HTML"); ?> which is extremely terse and convenient to use multiple times on a page.
     
  2. Make a method returning a string. Call the method KitGUI_Get_Content or KitGUI.GetContent or similar in your preferred style, it doesn't matter the name of the method as long as its easy for you to understand.
     
  3. Your method should have at least two parameters  (1) a string for the content ID and (2) a string for the content type. A possible third parameter (3) could be the account key or you can have that as a configuration item or hard code it within.
     
  4. You must ensure your content ID starts with a letter and follows with a series of any one of these: letters, numbers, underscores or dashes. If not, throw an exception as you should not proceed because the ID would be incompatible with KitGUI. The PHP example has a regular expression as well as the .NET example for your review.
     
  5. Within your method, declare a URL string variable instantiated with the following string:  "http://s3.amazonaws.com/kitgui/clients/" + [your account key] + "/ids/" + [your content ID] + ".txt"
     
  6. Within your method, declare a boolean variable for indicating the page is in edit mode or not. Check for the existence of a cookie defined as "kitgui" that has the value "1". If that condition is met, set the edit mode variable to true, otherwise false.
     
  7. Witin your method, declare a string variable for your HTML response.
     
  8. Within your method, make a cache key string variable which will hold the value "kitgui-content-" + [your content id]
     
  9. Within your method if your edit mode variable is false, assign the HTML to your server-side cache method's return value based on the cache key variable as the key, for example var HTML = getCache[cacheKey].
     
  10. Within your method, If your cache method returns a null resonse, assign the HTML variable to an empty string.
     
  11. Within your method, if in edit mode OR the HTML variable is empty string, make an HTTP Request with that URL variable and trap a 404 error or 404 header response and assign empty string to the HTML variable if 404 or and error occurs of any kind. If not error, get contents of response to the HTML string variable.
     
  12. Within your method, if in edit mode, assign your server-cache to the HTML variable contents based on the cache key variable, for example cache[cacheKey] = HTML
     
  13. If edit mode is true, return a string from your method in the following format :
    "<div style=\"display:inline-block\" class=\"kitgui-id-\"| + [your content ID] + " " + "kitgui-content-type-" + [your content type] + "\">" .+ [Your HTML variable contents] + "</div>"
    else, if its not in edit mode then simply return the contents of the HTML variable

 

Call your method wherever you want to edit content

  1. Wrap your method inline on your page with your desired HTML around it for example <div class="my-class"><%=KitGUI.GetContent("my-content-id","INLINE")%></div> or similar syntax. KitGUI's client-side script will attach to it and make it editable even if it does not exist yet. KitGUI does not add any markup to your edit if NOT in edit more.
     
  2. KitGUI works best with dynamic URLs in that you can define a single template with a URL pattern mapped to it such as "articles/[my-article-id]" where you can pass the article ID into the KitGUI content ID parameter. This will enable pages to be created on the fly as they are visited by editors and the content is saved.
     
  3. You can also make a persistent content ID that is always the same for all URL mappings for the template such as "my-left-navigation". Since it is the same on every page of the template, it will automatically contain a global navigation item and can be changed in any single page and reflect on all the pages by design. This type of logic has been implemented long before KitGUI was released to the public and is powering ecommerce sites with high traffic. The ability to quickly setup this scenario without needing to manage data items is quite freeing if you ever try it.