This is a custom element for Kontent by Kentico that generates a URL slug based on a text field or a custom value. It also checks for uniqueness of such value and can generated unique value if same url slug is found.
- Deploy the code to a secure public host
- See deploying section for a really quick option
- Follow the instructions in the Kontent documentation to add the element to a content model.
- The
Hosted code URL
is where you deployed to in step 1 - Pass the necessary parameters as directed in the JSON Parameters configuration section of this readme.
- The
- Deploy your server repeater for Preview API calls (details below)
Netlify has made this easy. If you click the deploy button below, it will guide you through the process of deploying it to Netlify and leave you with a copy of the repository in your GitHub account as well.
You need to specify the repeater
url, generates_from
and codename
parameters in order to make the element work. There are also optional force_uniqueness
and restricted_chars
parameters:
{
"repeater": "https://domain.com/repeater",
"generates_from": "title",
"codename": "custom_slug",
"force_uniqueness": "true", // default "false"
"restricted_chars": "[^a-zA-Z0-9]" // default [^a-zA-Z0-9]
}
repeater
-> A URL of a service you host on your server and that forwards JSON from Preview API based on "/items?elements.<url_slug_codename>[contains]=<url_slug_value>&depth=0" querygenerates_from
-> A codename of a source Text element you want your url slug to be generated fromcodename
-> A codename of your Custom URL Slug element (same codename across all types you want to check the uniqueness for)force_uniqueness
-> A true/false value that generates extra postfix to the url slug value in case the url slug is not uniquerestricted_chars
-> A set of characters (RegEx) you want the url slug to be restricted to
The value is saved as an array of [<url_slug_value>, <autogenerated/manual>] so you know whether the value was generated automatically from the source element or whether it was entered manually:
["abc","[manual]"]
Since custom element code needs to be publicly accessible, you can't call Preview API directly due to Preview token exposure. You need to create your own server repeater that checks the origin, asks Preview API with the token and returns data back.
With this custom element you can't use URLslug
macro in Preview urls. Please use ItemId
or Codename
macros instead.