Have you got content / text in templates, web parts and transformations, that is the same?
Is this text something the Kentico CMS user would love to amend easily and keep consistent, but it is difficult for them?
Well I am going to show you one way to achieve this.
A little background to the problem we want to solve
When creating Kentico web sites, imagine there is text / content all over the site, which is in different places and would be very difficult to keep it all consistent. We could develop something bespoke with Kentico API and store it in a database table, which would be hard to get to or even use Kentico UI Culture to create a New String or even use Kentico Resource Strings.
However we need a way for the Kentico CMS user to be able to access and manage them without expert knowledge and minimal training.
So I need to create something that is easy to use and manage. But what?
I need to think of a concept
I need something that would take a key / code / string and replace that with some content. The content should not just be in a plain format string and it should be able to handle HTML markup. This will be a challenge.
By using some Kentico API, creating a Kentico Custom Function and using Kentico Custom Tables, we can achieve this.
But how you might ask?
First we need to define the different steps
Populate the Custom Table with data that will be commonly used throughout the site. If the content is not common it could still be used to manage text that is hidden away in templates, web parts, transformations and the hard to get areas!
Create the Custom Function in the App Code area to talk to the Custom Table, using the code specified, so the text can be extracted and rendered out.
Apply the extracted text to different areas on the site.
Ok great, so lets show the steps in more detail.
Step 1 - Create Kentico Custom Table with the fields
Create the Custom Table
With the following fields
- VocabularyCode - This would be used to identify the content
- VocabularyContent - The content that would be used where the VocabularyCode is called
- VocabularyExists - This is just an area for the Kentico CMS user to put a cross reference to say where they have used this code.
For more information on creating Custom Tables view the Kentico Custom Tables documentation.
Handy Tip : Take a note of the Custom Table name for a later step :)
Step 2 - Populate the Kentico Custom Table with data
To do this you can add the data into the Custom Table. As we need to make sure the Kentico CMS user can perform this task and manage the data with ease.
Examples of the data that could be used are shown below
This just shows some of the example codes that could be used and the just a small sample of content that would be associated with them. Notice how some of them include HTML code, so we are trying to provide the Kentico CMS user as much control as possible.
Step 3 - Create the Kentico Custom Function in the App Code area
So the function I created for this is shown below.
This function, just takes the Vocabulary Code and then returns the Vocabulary Content from the custom table we created earlier using Kentico Custom Table API code.
One thing to notice in this function is that if an item from the Media Library is used within the content area e.g. an image and it's path contains a '~', it will be removed.
You can always add more to this function or call another function to add further requirements.
Don't forget you can also call this Custom Function using a Custom Macro. For more information on Registering Custom Macros.
Step 4 - Apply to different areas of the site within Kentico
All you now need to do is apply the Vocabulary Codes around the site. So some of the areas you would apply this could be in Transformations, Web Part code, Page Template layout and in Macros settings, by simply calling the Custom Function we created e.g.
<%# CustomFunctions.GetVocabularyContent("vacancy.applyButtonText") %>
Using this approach will allow the Kentico CMS user the ability to change the content for a set area where the code is used.
Another place you could take advantage of the Site Vocabulary System is within Custom Document Types or Custom Table fields. Allowing the Kentico CMS user the ability to choose their own code for certain elements on the page.
Kentico Best Practice Tip : If you are populating a Form Control field like a Drop Down field using SQL, for something like a Custom Document Type, then you need to remember to follow the Kentico Best Practice Tip - Adding SQL query to a document type.
Once you have set this up, then the Kentico CMS user just needs access to the Custom Table and they can amend existing content and add new codes with it's content without any additional permissions.
This is just one way we can ensure that the Kentico CMS user can manage similar content around the web site, utilising Kentico Custom Tables to achieve our goal. Why not give this a go to provide maxmimum flexibility to your web content editors?
Kentico Best Practice Tip - Adding SQL query to a document type