【问题标题】:TYPO3: How to render localized tt_content in own extensionTYPO3:如何在自己的扩展中呈现本地化的 tt_content
【发布时间】:2013-05-11 22:39:29
【问题描述】:

从自己的扩展中呈现 tt_content 元素的一种方法是:

function getCE($id)
{
    $conf['tables'] = 'tt_content';
    $conf['source'] = $id;
    $conf['dontCheckPid'] = 1;
    return $this->cObj->cObjGetSingle('RECORDS', $conf);
}

是否可以在 $conf 中添加一些内容以使 tt_content 本地化?假设我想要 sys_language_uid = 2 的 tt_content 行。

替代方案是使用“getRecordOverlay”,但随后 cObjGetSingle 的一些功能将丢失。

更新(适用于 TYPO3 4.5.10)

感谢您的反馈。我不知何故用“内容”的方式做错了。我没有从函数中得到任何回报。无论有无语言字段。

是否可以发布一个工作示例?假设我知道 tt_content uid 是 3389,它已被翻译成 uid 2 的语言。或者是一个简单工作示例的链接。

$conf = array(
    'table'   => 'tt_content',
    'select.' => array(
        'where'         => 'colPos=0 AND uid = 3389',
        'orderBy'       => 'sorting',
        'languageField' => 2 << if I leave this line out of the conf array I still get no result
    )
);
return $this->cObj->cObjGetSingle('CONTENT', $conf);        

BR。安德斯

【问题讨论】:

    标签: typo3


    【解决方案1】:

    您应该将RECORDS 替换为CONTENT 并相应地调整$conf 数组。 http://docs.typo3.org/typo3cms/TyposcriptReference/ContentObjects/Content/Index.html

    CONTENT 使用select http://docs.typo3.org/typo3cms/TyposcriptReference/Functions/Select/Index.html 并且可以再次使用languageField 来正确选择翻译内容。

    但是您必须将其连接到原始$id,因为内容元素确实通过l18n_parent 字段“知道”它们的原始元素。您可以使用where 或andWhere。

    【讨论】:

    • 使用 helmbert 发布的代码示例,您不会获得特定的内容元素,而是使用当前选择的语言获得“正常”列的全部内容。您应该在 where 子句中将 l18n_parent 设置为 $id,以确保您只会获得该特定元素的翻译。
    • 感谢您的帖子。即使我尝试阅读并理解您发布的链接,我也无法使其工作。我已经更新了我的问题。如果您有时间,请发布一个简单的工作示例。
    【解决方案2】:

    您可以尝试使用 CONTENT 代替 RECORDS:

    $conf = array(
        'table'   => 'tt_content',
        'select.' => array(
            'where'         => 'colPos=0',
            'orderBy'       => 'sorting',
            'languageField' => 'sys_language_uid' // <- Here!
        )
    );
    $conf['select.']['languageField'] = 'sys_language_uid';
    
    return $this->cObj->cObjGetSingle('CONTENT', $conf);
    

    【讨论】:

    • 感谢您的示例。我不能让它工作。我已经更新了我的问题。如果您有时间,请发布一个简单的工作示例
    猜你喜欢
    • 2010-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-10
    • 2016-06-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多