2012-09-13 60 views
0

我想在我的模板链接到第一个子页面(这是一个部分概述页面,所以总会有子页面可用)。该链接将始终具有相同的文本。Typoscript:如何获取当前页面的第一个子页面的ID?

如何获取第一个子页面的ID?

pagelink = TEXT 
pagelink { 
    value = Link to first child page 
    typolink { 
     parameter = [[id of first child page]] 
    } 
} 

回答

1

这里有一个简单的解决方案:

pagelink = HMENU 
pagelink { 
    # only display if there is a subpage 
    stdWrap.required = 1 
    # with value directory, the default special.value is the current page id 
    special = directory 
    # limit to 1 page 
    maxItems = 1 
    # link item 
    1 = TMENU 
    1 { 
     NO = 1 
    } 
} 

要覆盖网页的标题,用这个:

pageLink = HMENU 
pageLink { 
    # only display if there is a subpage 
    stdWrap.required = 1 
    # with value directory, the default special.value is the current page id 
    special = directory 
    # limit to 1 page 
    maxItems = 1 
    # link item 
    1 = TMENU 
    1 { 
     NO = 1 
     NO { 
      doNotLinkIt = 1 
      stdWrap.cObject = TEXT 
      stdWrap.cObject { 
       typolink.parameter.field = uid 
       # override text of menu item 
       value = Dummy Text 
      } 
     } 
    } 
} 
+0

好的,谢谢。给我正确的链接。你能告诉我如何替换菜单项中的页面标题吗?或者我必须用CSS隐藏它并使用换行来显示我需要的文本? – Tim

+0

@Tim是的,我把它添加到我的文章。 – Shufla

0

有几种方法可以做到这一点(例如,使用HMENU),但我会去为这一个,因为它是明确和容易,如果你一旦决定,使之更加复杂的修改(比如在页面标题某处文本链接,基于媒体字段渲染缩略图)。

pagelink = CONTENT 
pagelink { 
    table = pages 
    select { 
    pidInList = this 
    orderBy = sorting ASC 
    max = 1 
    } 
    renderObj = TEXT 
    renderObj { 
    value = Link to first child page 
    typolink { 
     parameter.field = uid 
    } 
    } 
} 

注意

  • 要在页面标题作为文本链接,取代value = Link to first child pagefield = title
  • 它只会是概述页面上显示正确的链接,而不是它的子页面。要在子页面上显示,必须采取不同的方法。
+0

我不建议这样做,因为无效的类型的页面(系统夹,间隔)也可以链接。还会显示设置了“在菜单中隐藏”的页面。 – Shufla

+0

@Shufla谢谢你的提示。也许我可以在'select'中添加'where'子句来过滤掉隐藏的页面......'where = doktype = 1 AND hidden = 0' – Tim

+0

@Tim当然你可以这样做,但是还有更多值尊重。 HMENU为你做了这一切。 – Shufla

相关问题