madhouse / slugger
Hashes the Id of an entry when it is saved and replaces the slug.
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 2 208
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 4
Forks: 2
Open Issues: 3
Type:craft-plugin
Requires
- craftcms/cms: ^3.0.0-RC1
- hashids/hashids: ^2.0
This package is auto-updated.
Last update: 2024-11-20 09:29:02 UTC
README
Slugger is a Craft plugin that hashes the Id of an entry when it is saved and replaces the slug with the hash.
This plugin uses the Hashids library to generate the slugs.
This plugin copies heavily from Alec Ritson's Slugged plugin for Craft 2. Thanks, Alec. đ (The section override works in this version btw.)
Requirements
This plugin requires Craft CMS 3.0.0 or later.
Installation
Visit the Plugin Store in your Craft 3 control panel and install from there. Slugger costs nothing. Visit the Plugin Store in your Craft 3 control panel. It costs nothing.
Or...
-
Open your terminal and go to your Craft project:
cd /path/to/project
-
Then tell Composer to load the plugin:
composer require madhouse/slugger
-
In the Control Panel, go to Settings â Plugins and click the âInstallâ button for Slugger.
Configuration
All configuration is done in the plugin settings page in the admin area.
Plugin settings
Salt
Set the salt to use when hashing
Default: Change me to something else
Default length
The length of the hash, this will be overwritten with any length defined for a section
Default: 8
Alphabet
The characters to use when generating the slug.
Default: abcdefghijklmnopqrstuvwxyz123456789
Sections
The only sections that will be listed are editable sections (no singles obvs). If you add a length to a section this will override the default set above. A section must be enabled for the hashing to happen, regardless of whether you add a length override or not.
Using Slugger
Enable your section in the settings. Make a new entry. Save it. Voila... hashed slug.
You can decode the hash using the decode
template variable.
{# get the hash value from the url #}
{% set hash = craft.app.request.getSegment(2) %}
{# use sluggerâs decode method to get the ID #}
{% set entryId = craft.slugger.decode(hash) %}
Support, issues, feedback
If you experience any problems please create a new issue here on the repo.
Brought to you by Madhouse