Tip #817: Display knowledge articles in the portals using custom templates

Dynamics 365 portals come with a specially crafted pages for browsing Knowledgebase Articles by category as well as for displaying the content. KB content page is based on a rewrite-style template and is not customizable.
It’s not difficult to put together an entity list and entity form to display the list of the articles and their content, however, the HTML content will be displayed:

HTML encoded

The reason is that entity forms in portals use textarea element to render the multi-line text content and the result, of course, is encoded.

There are two ways to solve the issue and get the content inline:

Do not define Details button for entity list that displays an overlay form. Instead, simply provide Web Page for details view. For that page use one of the liquid templates, e.g. Full Page Without Child Links and then insert the article by using liquid directly into the page content:

{% assign id = request.params['id'] %} 
{% assign kb = entities.knowledgearticle[id] %} 
{{ kb.content }} 

Knowledge article will be displayed in a separate page that portal will navigate to when you click the article number in the list.

If you insist on using overlay form, the solution is to replace <textarea> with a <div> element using javascript that you can define in the Custom JavaScript field:

$(document).ready(function() {
  var ctrl = $("textarea#content");
  var div = $("<div>").html(ctrl.text());
  ctrl.replaceWith(div);
});

Result:

HTML decoded

Tweet about this on TwitterShare on Facebook0Share on Google+0

Leave a Reply

Your email address will not be published. Required fields are marked *