英文:
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
你有两种可能性。
- 在这里有文档记录: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
}
...
- 第二种方法是用 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.
- 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
}
...
- 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
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论