[英]TYPO3: How to render translated content in extension
我正在開發TYPO3 6.0插件,該插件將當前頁面的子頁面顯示為選項卡。 例如,在以下頁面上,我的插件已插入TabRoot
:
如果請求TabRoot
,則插件的ActionController
在數據庫中查找子頁面標題和內容,並將所有收集的數據傳遞到Fluid模板。 然后呈現頁面,如下所示:
使用JS后,我總是根據選擇隱藏/顯示下面的內容。 我的問題是,我想根據當前的語言選擇顯示子頁面的翻譯內容 。 我該怎么做? 我已經嘗試了幾種方法,但是它們都不完美。 這些是我嘗試過的方法:
使用RECORDS
此方法不受所選語言的影響,它始終以默認語言返回內容:
//Get the ids of the parts of the page
$select_fields = "uid";
$from_table = "tt_content";
$where_clause = 'pid = ' . $pageId;
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
$select_fields,
$from_table,
$where_clause,
$groupBy='',
$orderBy='sorting',
$limit=''
);
$ids = '';
$firstIteration = true;
while ( $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc( $res ) ) {
if (!$firstIteration) $ids .= ",";
$ids .= $row ['uid'];
$firstIteration = false;
}
$GLOBALS['TYPO3_DB']->sql_free_result( $res );
//Render the parts of the page
$conf ['tables'] = 'tt_content';
$conf ['source'] = $ids;
$conf ['dontCheckPid'] = 1;
$content = $this->cObj->cObjGetSingle ( 'RECORDS', $conf );
根據TYPO3 使用CONTENTS
:如何在自己的擴展名中呈現本地化的tt_content ,這是做到這一點的方法,但是對我來說,這也返回使用默認語言呈現的內容。 它不受語言更改的影響。
$conf = array(
'table' => 'tt_content',
'select.' => array(
'pidInList' => $pageId,
'orderBy' => 'sorting',
'languageField' => 'sys_language_uid'
)
);
$content = $this->cObj->cObjGetSingle ( 'CONTENT', $conf );
使用VHS:Fluid ViewHelpers我安裝了vhs
擴展並嘗試使用<v:content.render />
呈現內容。 結果與CONTENTS
相同; 它僅適用於默認語言。
{namespace v=Tx_Vhs_ViewHelpers}
...
<v:content.render column="0" order="'sorting'" sortDirection="'ASC'"
pageUid="{pageId}" render="1" hideUntranslated="1" />
使用我自己的SQL查詢,我試圖獲取頁面的bodytext
字段,然后使用\\TYPO3\\CMS\\Frontend\\Plugin\\AbstractPlugin::pi_RTEcssText()
呈現它們。 此方法基於當前語言返回內容,但是問題是bodytext
並不包含完整的內容(圖像,其他插件等)。
$select_fields = "bodytext";
$from_table = "tt_content";
$where_clause = 'pid = ' . $pageId
. ' AND sys_language_uid = ' . $GLOBALS ['TSFE']->sys_language_uid;
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
$select_fields,
$from_table,
$where_clause,
$groupBy='',
$orderBy='sorting',
$limit=''
);
$content = '';
while ( $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc( $res ) ) {
$content .=
\TYPO3\CMS\Frontend\Plugin\AbstractPlugin::pi_RTEcssText( $row ['bodytext'] );
}
$GLOBALS['TYPO3_DB']->sql_free_result( $res );
我想念什么? 在使用CONTENTS
方法的情況下,為什么不使用當前語言呈現CONTENTS
?
在TYPO3 4.x中,您可以使用以下方法加載翻譯后的記錄:
t3lib_pageSelect->getRecordOverlay
t3lib_pageSelect->getPageOverlay
它們也可以在$GLOBALS['TSFE']->sys_page->getRecordOverlay()
。
最簡單的方法是使用cObject viewhelper從TypoScript
進行渲染。
在TypoScript
模板內部提供配置:
lib.myContent = CONTENT
lib.myContent {
...
}
順便說一句,您正在繞過TYPO3 CMS API。 請不要這樣做。 始終使用API方法來查詢數據。 例如\\TYPO3\\CMS\\core\\Database\\DatabaseConnection
始終在GLOBALS['TYPO3_DB']->
可用。 不要使用mysql
函數。
最重要的是,我相信您可以存檔使用純TypoScript
,而無需進行任何編程。 隨時提出新問題以獲取幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.