TYPO3: How to render localized tt_content in own extension

瘦欲@ 提交于 2019-12-24 08:39:08

问题


One way to render a tt_content element from own extension is this:

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

Is it possible to add something to $conf so tt_content is rendered localized? Lets say I want the tt_content row with sys_language_uid = 2.

Alternative is to use the "getRecordOverlay", but then some functionality from cObjGetSingle will be lost.

UPDATE (it is for TYPO3 4.5.10)

Thank you for feedback. I somehow do it wrong with the 'CONTENT' way of doing it. I get nothing back from the function. Neither with or without the languageField.

Is it possible to post a working example? Lets say I know the tt_content uid is 3389 and it has been translated to language with uid 2. Or a link to a simple working example.

$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. Anders


回答1:


You might try using CONTENT instead of 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);



回答2:


You should replace RECORDS with CONTENT and adjust the $conf array accordingly. http://docs.typo3.org/typo3cms/TyposcriptReference/ContentObjects/Content/Index.html

CONTENT makes use of select http://docs.typo3.org/typo3cms/TyposcriptReference/Functions/Select/Index.html and that again can use languageField for the proper selection of translated content.

But you will have to connect it to the original $id, since content elements do "know" their original element by the l18n_parent field. You can use where or andWhere for it.



来源:https://stackoverflow.com/questions/16597561/typo3-how-to-render-localized-tt-content-in-own-extension

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!