innoweb / silverstripe-remove-trailing-slash
Removes the trailing slash from page links.
Installs: 379
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:silverstripe-vendormodule
Requires
- silverstripe/cms: ^4.1
- silverstripe/vendor-plugin: ^1.0
This package is auto-updated.
Last update: 2023-04-16 00:30:44 UTC
README
Overview
Removes the trailing slash from page links.
SiteTree is the only class in Silverstripe that adds trailing slashes to links. This module cleans that up.
Requirements
- Silverstripe CMS 4.x
The changes from this module have been folded into core for Silverstripe 5, see 2780.
Installation
Install the module using composer:
composer require innoweb/silverstripe-remove-trailing-slash dev-master
Then run dev/build.
Configuration
Unfortunately, SiteTree::RelativeLink()
contains an issue, where the base link and action are joined with a forced /
. When no action is available, this leaves a trailing slash.
Because the extension point updateRelativeLink
is called before that join, you need to overwrite Page::RelativeLink()
with the following code:
/**
* Remove trailing slash from page links. SiteTree forces a trailing slash if no action is set, which doesn't
* make sense, really. Every other functionality in SS doesn't add the trailing slash, e.g. in HTTP and
* HTTPRequest classes.
*
* @see \SilverStripe\CMS\Model\SiteTree::RelativeLink()
*/
public function RelativeLink($action = null)
{
$link = parent::RelativeLink($action);
$link = rtrim($link, '/');
return $link;
}
See details to this issue in pull request 2677.
License
BSD 3-Clause License, see License