Slugs

A URL slug is the unique part of the address that identifies a specific document or category. As of Continuum #75 (17.5.0) unique slugs are generated for each document and category in the content management system.

Slug generation

For systems upgrading to 17.5.0, slugs are generated by a one time scheduled task that executes in the background to populate the JaduSlug database table.

Slugs for new content are automatically assigned by event listeners in the background of the application, as illustrated below:

Content type Event triggering generation Event triggering deletion
Document document.save When the document is first saved. document.delete When the document is deleted.
Category categorylist.published When a category list containing the category is first published. categorylist.published When a category list not containing the category is first published.

Slug format

Slugs are based on the title of a document or name of a category. Each slug is unique. Documents with the same title will have a unique slug.

The following rules are followed when generating a slug:

  • Spaces in the title will be replaced by dashes
  • Stop words will be removed from the title, unless the title consists solely of stop words
  • The title is changed to lowercase
  • Special characters are removed

Examples of stop words can be seen on the Yoast website - https://kb.yoast.com/kb/list-stop-words/

Content title Generated slug
Example Title example-title
Election results - General Election 2017 election-results-general-election-2017
Switch to e-billing and you could win up to $500 off your council tax bill switch-e-billing-win-500-off-council-tax-bill
Join the Pick Up for Pendle team! join-pick-pendle-team

Enabling slug values in URLs

On systems that are upgraded to 17.5.0, use of the new slug values must be enabled within the CMS by changing the value of USE_JADUSLUGS to true in the JaduConstants database table.

This can be done by visiting http://mydomain.com/jadu/install/set_contants.php or adjusting the value in the database table directly. If the value is adjusted in the database directly, the application cache must be cleared before the change will take effect. This can be done from the Utilities >> System Information >> Clear cache page.

To enable the configurable routes to use the new configuration, Please follow the steps given

  1. Vist utils/url_management in the control centre
  2. Update the destination of all routes
Route Name Destination
legacy_document_article_index /site/scripts/documents_info.php?categoryID=$1&documentID=$3
legacy_document_article /site/scripts/documents_info.php?categoryID=$1&documentID=$3&pageNumber=$5

Retrieving content from a slug value

<?php

use Jadu\Service\Container as ServiceContainer;
use Jadu\Continuum\Repository\Utility\UrlManagement\SlugDataMapper;
use Jadu\Continuum\Entity\Utility\UrlManagement\SlugEntity;
use Jadu\ContentType\DataMapper as ContentTypeDataMapper;

$slugDataMapper = new SlugDataMapper(
   ServiceContainer::getInstance()->getDB(),
   ServiceContainer::getInstance()->getCacheManager()
);

$contentDataMapper = new ContentTypeDataMapper(
   ServiceContainer::getInstance()->getSiteDB(),
   ServiceContainer::getInstance()->getCacheManager()
);

$categoryContentType = $contentDataMapper->getByTableName('JaduCategoryItems');
$documentContentType = $contentDataMapper->getByTableName('JaduDocuments');

// get document id from slug
$documentSlug = $slugDataMapper->getOne([
   'contentTypeId' => $documentContentType->getID(),
   'slug' => $documentSlug
]);
$documentId = $documentSlug->getItemId();

// get category id from slug
$categorySlug = $slugDataMapper->getOne([
   'contentTypeId' => $categoryContentType->getID(),
   'slug' => $categorySlug

]);
$categoryId = $categorySlug->getItemId();

results matching ""

    No results matching ""