TYPO3:使用Typoscript显示第一个子页面的内容

3
这是我想做的事情:在给定页面上,我想显示给定页面的第一个子页面的所有内容元素。我不能简单地使用快捷方式页面,因为我需要在子页面的元素之后显示其他内容元素。我该怎么做?
以下是我认为可以实现的示例代码片段,但我不知道如何构建选择器。有更好的方法吗?
# save current content
tmp.pagecontent < page.10.subparts.main-content

# clear the content of the main column
page.10.subparts.main-content >

# build a new object for this column as content-object-array
page.10.subparts.main-content = COA
page.10.subparts.main-content {
  10 = CONTENT
  10.table = tt_content
  10.select {
    # what should I put here?
  }
# re-insert the normal pagecontent to the page  
20 < tmp.pagecontent

你正在使用Templavoila吗?你可以引用这些项目。 - konsolenfreddy
不行,我使用的是模板自动解析器。我不能简单地引用这些项目,因为我想要的是第一个子页面的内容,而第一个子页面可能会随着我添加新页面而改变。因此,我想要显示的项目并不总是相同的。 - Charles Brunet
"select" 的行为类似于 SQL 查询。请查看此处 pidInList 的最后一个示例:http://wiki.typo3.org/TSref/CONTENT 对于您的情况,使用 RECORDS 可能更合适。http://wiki.typo3.org/TSref/RECORDS - Rito
2个回答

3

为他人添加答案。 第一步:指定当前页面的第一个子页面。 第二步:获取该子页面中所需的内容元素。

temp.content = COA
temp.content {
  10 = CONTENT
  10 {
    table = pages
    select {
      pidInList.field = uid
      orderBy = sorting ASC
      max = 1
      begin = 0
    }
    renderObj = COA
    renderObj {
      10 = CONTENT
      10 {
        table = tt_content
        select {
          languageField = sys_language_uid
          pidInList.field = uid
          orderBy = sorting
          #where = colPos = 10
        }
        stdWrap.wrap = |
      }
    }
  }
}

-1

我终于成功了!不过我不确定这是否是最好的方法。你认为呢?我应该把第二个选择也放到userFunc里面吗?

fileadmin/userfunc/mailArchive.php

<?php
class user_mailArchive {
    function getFirstChild($content, $conf) {
        $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
                'uid',                         // SELECT ...
                'pages',                       // FROM ...
                'pid='.intval($conf['pid']),   // WHERE...
                '',                            // GROUP BY...
                'sorting',                     // ORDER BY...
                '1'                            // LIMIT ...
            );
        $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
        if ($row) {
            return $row['uid'];
        }
        else {
            return '';
        }
    }
}

TS 模板

# fill the content of the main-column to a tmp.object
tmp.pagecontent < page.10.subparts.main-content

# clear the content of the main column
page.10.subparts.main-content >

includeLibs.mailArchive= fileadmin/userfunc/mailArchive.php

# build a new object for this column as content-object-array
page.10.subparts.main-content = COA
page.10.subparts.main-content {
  10 = CONTENT
  10 {
    table = tt_content
    select {
      pidInList.cObject = USER
      pidInList.cObject {
        userFunc = user_mailArchive->getFirstChild
        # parent page ID
        pid = 139
      }
      orderBy = sorting
    }
  }

# re-insert the normal pagecontent to the page  
  20 < tmp.pagecontent
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接