Using Date fields in Slugs
A slug field creates a URL-safe slug from the content of one (or more) of the other fields in an edit form. A common usage would be to create a slug from a title:
<perch:content id="title" type="text" label="Title">
<perch:content id="slug" type="slug" for="title">
Or you can use multiple fileds:
<perch:content id="name" type="text" label="Product Name">
<perch:content id="sku" type="text" label="Product SKU">
<perch:content id="slug" type="slug" for="name sku">
However, when it comes to dates you have to specify which part of the date (year, month, day, hour, minute) you want to add. So if you have a date field eventDate
and you want to use the year, you would use eventDate_year
:
<perch:content id="name" type="text" label="Event Name">
<perch:content id="eventDate" type="date" label="Event Date">
<perch:content id="slug" type="slug" for="eventDate_year name">
You can add multiple parts:
<perch:content id="slug" type="slug" for="eventDate_year eventDate_month eventDate_day name">
Native controls
Note that the above doesn’t work if you enable browsers native control for the date field:
<perch:content id="eventDate" type="date" label="Event Date" native>
In this case, you should be able to use eventDate
in the for
attribute like normal:
<perch:content id="slug" type="slug" for="eventDate name">