Cockpit provides a basic mechanism to handle slugs and we have the UniqueSlugs addon that enhances the core by providing uniqueness of slugs, however, and mostly because I have a scenario that requires a few more options I created a new addon that provides the possibility to define complete paths with dynamic tokens (e.g. blogs/[date:Y]/[field:title] or pages/[field:category]/[field:title], etc.)
This plugin works great! Iâm just confused as to how to actually implement the slugs once theyâre generated. How would I navigate to, for example, blogs/2019/newpost ?
From what I understand, the only way to retrieve a single entry in a collection is to use the api and ?filter the GET request or attach a JSON to a POST request.
Hey @ColinTravis, great you liked it⌠the slugs are just a representation on how you should access information in your frontend, remember that cockpit is a headless CMS. Letâs imagine you have a blog website, and you have a collection named blog, with a title, summary, date, etc⌠typically each entry should be accessed in form of blogs/<year>/<post-title>. Having that in slug helps you to build your routes in the frontend, that can be usefully mostly if you are using a static site generator like react-static or gatsby, where all blog collection entries are fetched and the routes are built using the slug as path.
Slugs only seem to refresh/update if a lug already exists for the entry. If I run refresh, entries that have not been âtouchedâ yet, wonât update.
@pauloamgomes can you speak to the other issue - updating/refresh fields that have not been touched? I get an error unless I open each entry and save it, then the refresh works.
My format: {"format": "[collection:name]/[callback:slugDateParts]/[field:name]"}
only returns the name of the entry e.g. â/my-first-eventâ, so I have some questions/remarks:
[collection:name] doesnât work
callback function doesnât work.
Where to place the callback function?
How to address a field name in a callback function? Like this â$entry[fieldName]â?
I donât know whether it is relevant, but the BetterSlug-field was added to an existing collection.
Regards,
Zignature
p.s.
Thanks for all your add-on work! Much appreciated
Thanks @Zignature for pointing the issue, in fact the collection:name wasnât working due a regression. Should be ok now.
Regarding the callback function that is described in the readme, in such case you should put your function in a boostrap.php file, the function should be like:
function slugDateParts($entry, $app, $lang = FALSE) {
return $entry['fieldName'];
}
I got the callbacks working. Had to split them into 3 functions because lime/helper/utils.php changed my slashes into dashes.
Hereâs what I got in config/bootstrap.php:
Hi, I get an error message (âsystem errorâ) when I try to save a collection since installing the addon. The collection is being saved, but the confirmation message has been replaced with the error message.