0
votes

I am developing a TYPO3 6.0 plugin that shows the subpages of the current page as tabs. For example, on the following pages my plugin is inserted on TabRoot:

Example TYPO3 pages

If TabRoot is requested, the plugin's ActionController looks up the database for the subpage titles and contents and passes all gathered data to a Fluid template. The page is then rendered like the following:

Tab selector functionality

With JS in place I always hide/show content below based on the selection. My problem is that I want to show the translated content of the subpages based on the current language selection. How am I able to do this? I've tried it with several methods, but neither of them was flawless. These are the methods I've tried:


Using RECORDS This method is not affected by the selected language, it always returns the content in the default language:

//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 );

Using CONTENTS According to TYPO3: How to render localized tt_content in own extension, this is the way to do it, however for me this also returns the content rendered with the default language. It is not affected by a language change.

$conf = array(
    'table' => 'tt_content',
    'select.' => array(
            'pidInList' => $pageId,
            'orderBy'  => 'sorting',
            'languageField' => 'sys_language_uid'
    )
);
$content = $this->cObj->cObjGetSingle ( 'CONTENT', $conf );

Using VHS: Fluid ViewHelpers I installed the vhs extension and tried to render the content with <v:content.render />. The result is the same as with CONTENTS; it only works with the default language.

{namespace v=Tx_Vhs_ViewHelpers}

...

<v:content.render column="0" order="'sorting'" sortDirection="'ASC'"
        pageUid="{pageId}" render="1" hideUntranslated="1" />

Using my own SQL query I've tried to get the bodytext fields of the page and then render those with \TYPO3\CMS\Frontend\Plugin\AbstractPlugin::pi_RTEcssText(). This method returns the content based on the current language, however the problem is that bodytext's do not contain the complete content (images, other plugins, etc).

$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 );

What am I missing? Why isn't the content rendered with the current language in the case of the CONTENTS method?

2
Just an idea: If you are using fluid, maybe using the vhs extension, specifically one of the *Menu-ViewHelpers could do the trick? fluidtypo3.org/viewhelpers/vhs/master/Page/Menu/…Jost
@Jost I managed to render the page content with the default language, but I couldn't get this to work with a different language.Daniel Szalay
Why using an extension? You can do this with pure TS. I suggest to reduce the extension to a cObject viewhelper and doing the logic in TypoScript. t3brightside.com/blog/article/…pgampe
@pgampe Thanks! I did not try it yet, but I accepted your answer since you have been helping me a lot already. Building an extension feels natural to me, since then I just have to add it to the desired pages on the backend. Also, the CONTENTS method is based on TS, so I would expect it to work. But then again, I am new to TYPO3 and I understand PHP way better :)Daniel Szalay

2 Answers

0
votes

In TYPO3 4.x you could use the following methods to load the translated record:

  • t3lib_pageSelect->getRecordOverlay
  • t3lib_pageSelect->getPageOverlay

They are also available at $GLOBALS['TSFE']->sys_page->getRecordOverlay().

0
votes

Easiest way is to use the cObject viewhelper to render right from TypoScript.

And inside your TypoScript template provide the configuration:

lib.myContent = CONTENT
lib.myContent {
  ...
}

BTW, you are bypassing the TYPO3 CMS API. Please do not do so. Always use the API methods to query for data. e.g. \TYPO3\CMS\core\Database\DatabaseConnection is always available at GLOBALS['TYPO3_DB']->. Do not use the the mysql function.

On top of that, I believe that you can archive whatever you are trying to do with pure TypoScript, without the need to program anything. Feel free to ask a new questions to get help on this.