Search code examples
typo3typoscripttypolink

Why are my typolinks t3: not replaced if I fetch them with CONTENT?


I have Typoscript like this:

lib.rccProcessTexts = CONTENT
lib.rccProcessTexts {

    table = tt_content
    select {
        pidInList = {$rcc.ids.pidRccProcessTexts}
    }

    renderObj = COA
    renderObj {
       10 = TEXT

       # The field tt_content.bodytext holds the content text.
       10.stdWrap.field = bodytext

       10.stdWrap.wrap = <div data-phase-id="{field:colPos}">|</div>
       10.insertData = 1
 }

wrap = <div class="hidden" data-process-texts>|</div>
}

So this Typoscript fetches content from tt_content. Any typolinks (t3://...) are not replaced by real links (like https://www.example.com/go/to/page).

How can I make TYPO3 create real links?


Solution

  • You have 2 possibilities.

    1. is documented here: https://docs.typo3.org/m/typo3/reference-typoscript/main/en-us/ContentObjects/Text/Index.html

    It is to add this parseFunc to the TEXT object:

    10.stdWrap.parseFunc < lib.parseFunc_RTE
    

    This will cause the text to be parsed as usual.

    So finally:

    ...
    ...
    renderObj = COA
        renderObj {
           10 = TEXT
    
           # The field tt_content.bodytext holds the content text.
           10.stdWrap.field = bodytext
    
           10.stdWrap.wrap = <div data-phase-id="{field:colPos}">|</div>
           10.insertData = 1
           10.stdWrap.parseFunc < lib.parseFunc_RTE
     }
     ...
    
    1. The second is to write a userfunc with PHP.

    10.stdWrap.parseFunc.userFunc = My\Way\To\MyClass.php->doSomething()

    Then just add Class.php with doSomething() to the Classes/UserFunc folder. The class is like so:

    <?php
    namespace My\Way\To;
    
    class MyClass
    {
      /**
       * @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
       */
      public $cObj;
    
    
    /**
        *
        * @param  string When custom methods are used for data processing (like in stdWrap functions), the $content variable will hold the value to be processed. When methods are meant to just return some generated content (like in USER and USER_INT objects), this variable is empty.
        * @param  array  TypoScript properties passed to this method.
        * @return string The input string reversed. If the TypoScript property "uppercase" was set, it will also be in uppercase. May also be linked.
        */
        public function doSomething(string $content, array $conf): string 
        {
           // Have fun
        }
    
    
    }