【发布时间】:2014-07-10 01:51:51
【问题描述】:
我正在开发一个 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 );
使用CONTENTS 根据TYPO3: How to render localized tt_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 我安装了 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方法的情况下,为什么没有用当前语言渲染内容?
【问题讨论】:
-
只是一个想法:如果您使用流体,也许使用 vhs 扩展,特别是 *Menu-ViewHelpers 之一可以做到这一点? fluidtypo3.org/viewhelpers/vhs/master/Page/Menu/…
-
@Jost 我设法用默认语言呈现页面内容,但我无法让它使用其他语言。
-
为什么要使用扩展?你可以用纯 TS 做到这一点。我建议减少对 cObject viewhelper 的扩展,并在
TypoScript.t3brightside.com/blog/article/… 中执行逻辑 -
@pgampe 谢谢!我还没有尝试过,但我接受了你的回答,因为你已经帮了我很多。构建扩展对我来说感觉很自然,从那时起我只需将其添加到后端所需的页面即可。此外,
CONTENTS方法基于 TS,所以我希望它能够工作。但话又说回来,我是 TYPO3 的新手,我对 PHP 的理解更好:)
标签: typo3