is there a possibility to add rel="nofollow" to external links made with the link wizard from tca in the backend? (EG Link for Headlines in all content elements, link on images, external link in page tree).
The only way i found was the link handler in ck_editor.
Thanks!
I forked the extension noopener
and made some adjustments to allow TypoScript configuration. As of now the TypoScript is not included yet but I post here the options:
config.tx_noopener {
useDefaultRelAttribute = false
relAttribute = nofollow
}
useDefaultRelAttribute
is boolean (only false or 0 triggers something).
relAttribute
can be any string, also with spaces.
With this TypoScript-option it's possible to configure it different for specific pages.
The extension is available here: https://github.com/DavidBruchmann/noopener .
After adding TypoScript I will make a pull request to the original extension.
EDIT:
If you have access to configure single links like headlines, you can add now one or several css-classes with prefix rel-
. If you enable the handling by noopener
those classes will be used to create the rel
-Attribute.
Furthermore you can configure if the classes shall be removed then from the classes-attribute.
Example:
I added a title
in a content-element and a link in the corresponding field below. For the link I added these classes rel-nofollow rel-something col-right kunterbunt
.
This is the TypoScriptSetup:
config.tx_noopener {
useDefaultRelAttribute = false
# relAttribute = nofollow
useCssClass = 1
keepCssRelClass = 0
}
The option useCssClass
dis- or enables the handling by css-class completely.
keepCssRelClass
determines if the value shall be removed from the class-attribut when it's used for the rel-attribute.
Additional the values in the class-attribute are only accepted if in the list of allowed values for the a-element according to this list:
https://developer.mozilla.org/en-US/docs/Web/HTML/Link_types
I know this filter might be undesired for some cases like lightbox where some other keywords are used but doing it without filter looked a bit scary and insecure for me, as it would enable editors to enter everything. But keep in mind that the extension noopener
is used only for external links, usage for internal links is in general possible but would change the basic idea of the extension.
The result from the configured link above is this:
<a rel="nofollow" href="..." class="rel-something col-right kunterbunt">...</a>
As you can see, the css-class rel-nofollow
is shifted to the rel
-attribute, rel-something
is left untouched as it's not in the list of allowed values and the other css-classes never have the rel
-prefix anyway.
EDIT
The pull request can be found here: https://github.com/georgringer/noopener/pull/6
Solving your question without extension first I thought about TypoScript lib.parseFunc
.
The fluid-templates are just parsed without that function and you have to adjust the templates. Looking in the ViewHelper TypoLinkViewHelper
you can see a list of allowed arguments:
public function initializeArguments()
{
$this->registerArgument('parameter', 'string', 'stdWrap.typolink style parameter string', true);
$this->registerArgument('target', 'string', '', false, '');
$this->registerArgument('class', 'string', '', false, '');
$this->registerArgument('title', 'string', '', false, '');
$this->registerArgument('additionalParams', 'string', '', false, '');
$this->registerArgument('additionalAttributes', 'array', '', false, []);
$this->registerArgument('useCacheHash', 'bool', '', false, false);
$this->registerArgument('addQueryString', 'bool', '', false, false);
$this->registerArgument('addQueryStringMethod', 'string', '', false, 'GET');
$this->registerArgument('addQueryStringExclude', 'string', '', false, '');
$this->registerArgument('absolute', 'bool', 'Ensure the resulting URL is an absolute URL', false, false);
}
The word external
is not existing in the VH, so I assume you had to extend it and use your own VH. I never verified what the extension(s) for those purposes are doing in detail, probably they use some hook or service as they probably never require change of the templates.
I tried to change the Partial-template for the headlines and it works, just the separation between internal and external links is missing without further changes.
Template files reside in typo3/sysext/fluid_styled_content/Resources/Private
and you could copy them into an own extension and change the default location accordingly.
<f:if condition="{header}">
<f:switch expression="{layout}">
<f:case value="1">
<h1 class="{positionClass}">
<f:link.typolink parameter="{link}">{header}</f:link.typolink>
</h1>
</f:case>
<f:case value="2">
<h2 class="{positionClass}">
<f:link.typolink parameter="{link}" additionalAttributes="{rel:'nofollow'}">{header}</f:link.typolink>
</h2>
</f:case>
...
So probably the usage of the extension noopener proposed by @Julian Hofmann is the best and smartest solution. if you never need only a few but general changes.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.