为什么我的typolinks(t3)如果我使用CONTENT获取它们,就不会被替换?

huangapple go评论44阅读模式
英文:

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

问题

我有类似这样的 Typoscript 代码:

lib.rccProcessTexts = CONTENT
lib.rccProcessTexts {

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

    renderObj = COA
    renderObj {
       10 = TEXT

       # tt_content.bodytext 字段包含内容文本。
       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>
}

因此,这个 Typoscript 从 tt_content 中获取内容。任何 typolink(`t3://...`)都不会被替换为实际链接(如 `https://www.example.com/go/to/page`)。

我如何让 TYPO3 创建实际链接?
英文:

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?

答案1

得分: 3

你有两种可能性。

  1. 在这里有文档记录:https://docs.typo3.org/m/typo3/reference-typoscript/main/en-us/ContentObjects/Text/Index.html

要将此 parseFunc 添加到 TEXT 对象中:

10.stdWrap.parseFunc < lib.parseFunc_RTE

这将使文本像往常一样被解析。

最终:

...
...
renderObj = COA
    renderObj {
       10 = TEXT

       # tt_content.bodytext 字段包含内容文本。
       10.stdWrap.field = bodytext

       10.stdWrap.wrap = <div data-phase-id="{field:colPos}">|</div>
       10.insertData = 1
       10.stdWrap.parseFunc < lib.parseFunc_RTE
 }
 ...
  1. 第二种方法是用 PHP 编写一个 userfunc。
10.stdWrap.parseFunc.userFunc = My\Way\To\MyClass.php->doSomething()

然后只需在 Classes/UserFunc 文件夹中添加 Class.php 和其中的 doSomething() 方法。类如下:

<?php
namespace My\Way\To;

class MyClass
{
  /**
   * @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
   */
  public $cObj;


/**
    *
    * @param  string 当用于数据处理的自定义方法时(例如在 stdWrap 函数中),$content 变量将保存要处理的值。当方法旨在仅返回一些生成的内容(例如在 USER 和 USER_INT 对象中),此变量为空。
    * @param  array  传递给此方法的 TypoScript 属性。
    * @return string 反转的输入字符串。如果设置了 TypoScript 属性“uppercase”,它也将为大写。也可能是链接的。
    */
	public function doSomething(string $content, array $conf): string 
	{
       // 玩得开心
	}


}
英文:

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 &lt; 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 = &lt;div data-phase-id=&quot;{field:colPos}&quot;&gt;|&lt;/div&gt;
       10.insertData = 1
       10.stdWrap.parseFunc &lt; lib.parseFunc_RTE
 }
 ...
  1. The second is to write a userfunc with PHP.

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

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

&lt;?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 &quot;uppercase&quot; was set, it will also be in uppercase. May also be linked.
    */
	public function doSomething(string $content, array $conf): string 
	{
       // Have fun
	}


}

huangapple
  • 本文由 发表于 2023年2月19日 07:12:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/75496966.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定