Forum
List and detail - creating a unique slug
Because it's likely the title could be the same for more than one item, I'd like to create a unique slug. I thought I might be able to make a slug using the title and also the item ID, but it's not working. What am I doing wrong?
<perch:content id="slug" type="slug" for="_id" />
The
for
fields need to exist in the form.Ok, so I needed to add this to my template:
Thanks Drew.
The problem with the above is that it creates a field in the form for the editor to see with the id number in. adding type="hidden" to the _id causes it not to be passed into the slug.
Yes, I can see how that would be a problem.
Why if it's hidden in the form is it not passed to the slug?
Is there any way to get a unique slug?
Hidden items aren't included in the form, so they're not in the post.
It's something we need to look at, as I've indicated.
Ok, thanks very much Drew.
Greetings, I'm have the same trouble with duplicating titles. I'm just curious if the status on this has changed?
Many thanks! Nick
Yes, I'm having the same problem. I have a list of Job Postings that link to a detail page, but because the slug isn't unique (many job titles have the same name) it isn't working properly. There must be something unique about an entry that can be passed in a list/detail scenario, no?
Use a date field in combination with the job title to generate the slug?
From Perch documentation:
https://docs.grabaperch.com/docs/templates/attributes/type/slug/
I'm using multiple space-separated id's to generate the slog, but only the first id is being used in the created slug.
<li><a href="detail.php?s=<perch:content id="slug" type="slug" for="title landtrust" />"> <perch:content id="title" type="text" />, <perch:content id="landtrust" type="text" /></a></li>
Asking again: is there a way to generate a unique slug. I've tried using a space-separated list of ids, but that doesn't seem to be working. For example, in my template I have two fields:
<perch:content id="eventTitle" label="Title" title="true" />
<perch:content id="eventDateTime" format="F j, Y, ga" label="Date" type="date" time="true" />
and I would like to generate a unique slug by combining the two fields, so I have:
<perch:content id="slug" type="slug" for="eventTitle eventDateTime" />
Only the first field is used in the slug.
Anyone?
Order of the fields doesn't seem to matter, my code below skips the
eventDateTime
and only makes theeventTitle
the slug, so field order doesn't matter. I tested it with another text field and it worked as expected.Perhaps date fields aren't able to made into slugs...