Ad

Check Link Type For TYPO3 / FLUID Template

- 1 answer

In my typo3 project I have a fluid template that renders bodytext from CMS:

<f:section name="Main">
         <div class="RteContent">
               <f:format.html>{data.bodytext}</f:format.html>
         </div>
</f:section>

Now, in the RTE you can set links for files or links for pages. My goal is to have a different styling for file links. Is there any way to find out what kind of links are being set and then apply an according CSS style for this type of file link?

Ad

Answer

parseFunc

The HTML output of RTE content is controlled by a parseFunc (see https://docs.typo3.org/other/typo3/view-helper-reference/master/en-us/typo3/fluid/latest/Format/Html.html). The default is lib.parseFunc_RTE but you can use your own.

If you are a TypoScript magician (I am not) it can do pretty amazing things (https://docs.typo3.org/m/typo3/reference-typoscript/master/en-us/Functions/Parsefunc.html#makelinks). I would look into makelinks.http.ATagParams (stdWrap).

CSS

Yet there is probably a much easier way. By using TYPO3's fixed file storage URL to our advantage we can use CSS selectors to match links to files.

This might need adapting depending on your configuration which might influence link generation (config.baseUrl/absRefPrefix)

a[href*="/fileadmin/"] {
  background: yellow
}

or

a[href^="/fileadmin/"] {
  background: yellow
}

or

a[href$=".pdf"] {
  background: yellow
}
Ad
source: stackoverflow.com
Ad