Kentico has lots of feature and functions to help the developer getting things done easy and quickly. This series will contain quick short posts about handy features and functions to make your developer life more easy.
So quite often when creating a new Page Type you'll have to include a relation to some other item. This could be a Custom Table Item, an other page or perhaps even a User. You don't want to use the related pages.
Easy you think, just create a field and select a 'Custom table item selector' control. (Or the Page/User selector for the other two scenario's I mentioned). And you're done, right?
But what if you want to limit the results, add a where clause, save something else than the default field... You think for two seconds about the drop down menu, radio button or multiple choice field... But end up writing your own custom form control.
Turns out that's not needed. Those three default controls come with lots of features out of the box.
When you configure the Radio buttons
control, you can select the Data source
. In this case I needed to select an item from my Locations custom table
. But I wanted to show both the Location Name and its type. Since the type will help the editor more to determine which item to select.
Just define the columns you need to display (and the one you want saved in the DB) and put them in the Transformation
field as a Macro. Kentico will resolve them on the fly.
Note: don't forget to specify all columns you need in your select.
The result could look something like this:
Same way you could configure the drop down menu control.
You can add extra static content to help display the result. I've put the location between extra parenthesis
. But you could also add other things or even complete Kentico macro's to display by your need.
Also this can come in handy if you need to make a more advanced selection. Although not that adavnced lets say we want to select all nodes that are published before today of specific page type.
In this case I've configure the Multiple choice control like you can see below.
Since the pages can have the same name I've included the Node Alias Pat
h for the editors.
There are numerous ways you can extend and configure this to your needs. Lots of scenarios can be solved using this method!