我正在开发一个TYPO3 6.0插件,它将当前页面的子页显示为选项卡。例如,在下面的页面中,我的插件被插入到TabRoot上

如果请求TabRoot,插件的ActionController将查找数据库中的子页面标题和内容,并将所有收集到的数据传递给流畅的模板。然后,页面呈现如下所示:

有了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 );使用 CONTENTS,根据content in own extension,这是实现它的方法,但是对于我来说,它也返回默认语言呈现的内容。它不受语言变化的影响。
$conf = array(
'table' => 'tt_content',
'select.' => array(
'pidInList' => $pageId,
'orderBy' => 'sorting',
'languageField' => 'sys_language_uid'
)
);
$content = $this->cObj->cObjGetSingle ( 'CONTENT', $conf );使用VHS: Fluid ViewHelpers i安装了vhs扩展,并尝试用呈现内容。结果与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方法的情况下,为什么当前语言没有呈现内容?
发布于 2014-05-27 22:52:01
最简单的方法是使用cObject viewhelper从TypoScript中直接呈现。
在您的TypoScript模板中提供以下配置:
lib.myContent = CONTENT
lib.myContent {
...
}顺便说一句,您正在绕过TYPO3 CMS API。请不要这样做。始终使用API方法查询数据。\TYPO3\CMS\core\Database\DatabaseConnection在GLOBALS['TYPO3_DB']->总是可用的。不要使用mysql函数。
最重要的是,我相信您可以用纯TypoScript来归档您想要做的任何事情,而不需要编写任何程序。你可以问一个新的问题来寻求帮助。
发布于 2014-05-23 08:09:50
在TYPO3 4.x中,可以使用以下方法加载已翻译的记录:
t3lib_pageSelect->getRecordOverlayt3lib_pageSelect->getPageOverlay它们也可以在$GLOBALS['TSFE']->sys_page->getRecordOverlay()上使用。
https://stackoverflow.com/questions/23782883
复制相似问题