TypoScript Setup Reference

Configure prefix and suffix

plugin.tx_contentslug

Property Data type Default
urlFragmentPrefix data-type-cobject TEXT cObject with current UID
urlFragmentSuffix data-type-cobject TEXT cObject with current UID
replaceFragmentInPageLinks boolean 1
checkForHiddenHeaders boolean 1

urlFragmentPrefix

Property
urlFragmentPrefix
Data type
data-type-cobject
Description

This cObject can be used to render a prefix for the human-readable URL fragment.

Prefix, suffix, and fragment are assembled in the custom variable fragmentIdentifier of lib.contentElement.

Default:

plugin.tx_contentslug.urlFragmentPrefix = TEXT
plugin.tx_contentslug.urlFragmentPrefix {
    field = uid
    stdWrap.noTrimWrap = |c|-|
    if.isTrue = {$plugin.tx_contentslug.settings.renderPrefix}
}
Copied!

Result:

c<uid>-<human-readable-fragment>
c123-section-of-interest
Copied!

urlFragmentSuffix

Property
urlFragmentSuffix
Data type
data-type-cobject
Description

This cObject can be used to render a suffix for the human-readable URL fragment.

Prefix, suffix, and fragment are assembled in the custom variable fragmentIdentifier of lib.contentElement.

Default:

plugin.tx_contentslug.urlFragmentSuffix = TEXT
plugin.tx_contentslug.urlFragmentSuffix {
    field = uid
    stdWrap.noTrimWrap = |-||
    if.isTrue = {$plugin.tx_contentslug.settings.renderSuffix}
}
Copied!

Result (if activated):

<human-readable-fragment>-<uid>
section-of-interest-123
Copied!

settings.checkForHiddenHeaders

Property
settings.checkForHiddenHeaders
Data type
boolean
Description

By default, this extension renders the human-readable fragment as an id attribute on the content element's header. Therefore, a given fragment will not be used for content elements that have a hidden (non-rendered) header.

If you disable this setting, fragment links are replaced even if the content element's header is hidden. You will then need to render this attribute on a different HTML tag. You will also need to hide the checkbox "Set link to #anchor", or migrate the corresponding HTML markup as well.

Recommendation: add the id attribute to the Fluid layout of content elements.

EXT:site_package/Resources/Private/Layouts/ContentElements/Default.html
<div id="c{data.uid}" class="frame frame-{data.frame_class} frame-type-{data.CType} frame-layout-{data.layout}{f:if(condition: data.space_before_class, then: ' frame-space-before-{data.space_before_class}')}{f:if(condition: data.space_after_class, then: ' frame-space-after-{data.space_after_class}')}">
    <f:if condition="{data._LOCALIZED_UID}">
        <a id="c{data._LOCALIZED_UID}"></a>
    </f:if>

    <!-- Add these lines: -->
    <f:if condition="{fragmentIdentifier}">
        <div id="{fragmentIdentifier}"></div>
    </f:if>

    <!-- etc. -->
</div>
Copied!
Default
1 (via TypoScript constant)

Assemble the fragmentIdentifier variable

This variable is available in all Fluid templates of EXT:fluid_styled_content and allows to configure the complete URL fragment at a central place.

lib.contentElement {
    // Override default templates of fluid_styled_content:
    partialRootPaths.101 = EXT:content_slug/Resources/Private/Overrides/fluid_styled_content/Partials/
    templateRootPaths.101 = EXT:content_slug/Resources/Private/Overrides/fluid_styled_content/Templates/

    // Build a complete fragment identifier with possible prefix and suffix:
    variables {
        fragmentIdentifier = COA
        fragmentIdentifier {
            if.isTrue.field = tx_content_slug_fragment

            10 =< plugin.tx_contentslug.urlFragmentPrefix

            20 = TEXT
            20.field = tx_content_slug_fragment

            30 =< plugin.tx_contentslug.urlFragmentSuffix

            stdWrap.trim = 1
        }
    }
}
Copied!

Use FragmentIdentifierProcessor for "Section Index" menus

The menu content elements of type "Section Index" are built with DataProcessors.

To get the configured fragmentIdentifier variable for each of the linked content elements in these menus, the custom FragmentIdentifierProcessor is needed.

// Process 'fragmentIdentifier' variable in section menus:
tt_content.menu_section.dataProcessing.10.dataProcessing.20.dataProcessing.5 = Sebkln\ContentSlug\DataProcessing\FragmentIdentifierProcessor
tt_content.menu_section_pages.dataProcessing.10.dataProcessing.20.dataProcessing.5 = Sebkln\ContentSlug\DataProcessing\FragmentIdentifierProcessor
Copied!

Sanitize custom data with postUserFunc

In case you append or prepend some custom strings, you can use the fragment evaluation to sanitize the completed URL fragment again:

urlFragmentSuffix = TEXT
urlFragmentSuffix {
    field = subheader
    if.isTrue.field = subheader
    stdWrap.noTrimWrap = |-||
}

lib.contentElement.variables.fragmentIdentifier {
    stdWrap.postUserFunc = Sebkln\ContentSlug\Evaluation\FragmentEvaluation->sanitizeFragment
}
Copied!