Create a slug system

    To start building your slug system you need a string field as a base for your slug, in this example we will use title.

    You will also need another string field that contains the slugified value of your title, in this case we will use slug.

    • Click on the Article link in the left menu.
    • Then on the + Add New Article button.
    • And finally on the Configure the layout button.

    Here we will be able to setup the slug field.

    • Click on the slug field.
    • At the bottom of the page, edit the placeholder value to Generated automatically based on the title.
    • Don’t forget to save your updates.

    View before

    For that you will have to install slugify node module in your application.

    When it’s done, you have to update the life cycle of the Article Content Type to auto complete the slug field.

    Path — ./api/article/models/Article.js

    1. const slugify = require('slugify');
    2. module.exports = {
    3. /**
    4. * Triggered before user creation.
    5. */
    6. lifecycles: {
    7. async beforeCreate(data) {
    8. data.slug = slugify(data.title, {lower: true});
    9. }
    10. },
    11. async beforeUpdate(params, data) {
    12. if (data.title) {
    13. data.slug = slugify(data.title, {lower: true});
    14. }
    15. },
    16. },

    You will be able to find your articles by slug with this request