Three tips for working with Kentico CMS

Jared Johnson, 23 November 2011

Recently I have been editing a website created using Kentico CMS. While powerful it is often quite hard to find information about achieving certain tasks on the web, leaving you with only the official documentation. To help with this here are 3 things I learnt how to do in Kentico CMS.

Three tips for working with Kentico CMS

1.  How to create a new Transformation

Transformations are small code files that take data from the Kentico CMS database and turn it into html code for display. Most web parts or widgets that display data of some kind will require one to function. However, you quickly notice when adding the web-part that you can only select or edit existing Transformations and not create a new Transformation from inside the web parts properties window. Here's how to create a new Transformation:

a. Switch from CMS Desk and go into the site manager

b. Click the development tab

c. Select Document types from the left navigation this gives you a page containing different categories of Transformations

d. Click the green pencil on an existing category or create a new category to in which to store your Transformation

e. Click on the Transformations tab

f. Click the new Transformations hyperlink

2.  Converting between different time formats

When adding a new culture in addition to the standard US culture, I quickly noticed that many of the web parts were now causing errors. This was because while the {%currentdatetime%}  macro used in the web parts was returning the date using the new culture using the DD/MM/YYYY format, the data it was accessing was still stored using the MM/DD/YYYY format. To fix this I appended the culture macro of format | (culture) <code> to the values that needed to be converted. For this and other useful macros checkout this page

 Three tips for working with Kentico CMS

3.  Correcting URLs when using the Forum posts viewer to display group forums

With a Forum posts viewer if you leave the Forum groups property blank and tick the Show group posts checkbox, the Forum posts viewer will access the posts from all the groups internal forums (as long as they have view access to non-members). However when using this the URL in the posts it displays is wrong, for me it uses ~/Group-pages/... instead of ~/Groups/... .

To fix this I created a new Transformation and copied the contents of the transformation I was using before into it.

I then added a class id to the <a> tag that displays the wrong link, then using JavaScript I used the string replace method to correct the URL of all the <a> tags on the page with that class id like this:

var aTags = document.getElementsByClassName('forumGroupLink');<br>
for (var i=0; i<aTags.length; i++) {<br>
var strRplc=aTags[i].href;<br>
strRplc=strRplc.replace("Group-pages", "Groups");<br>
aTags[i].href=strRplc;<br>
}

Hopefully these tips will be helpful and save you some time googling around.