Switch detail view based on news item's category

How to treat news detail view different for a all subcategories of a specific root category (this example only works for two levels of categories). It shows how to use v:switch, v:variable.typoscript and v:iterator ViewHelpers.

Description Switch news detail view template based on parent category
Author benjaminrau
Creation date 2014-09-12T10:28:36.000Z
Extensions
  1. FluidTYPO3.Vhs
Tags
  1. ViewHelpers
Files
  1. Detail.html
<f:section name="Main">
<f:if condition="{newsItem}">
<v:switch value="{newsItem.categories -> v:iterator.extract(key: 'parentcategory') -> v:iterator.extract(key: 'uid') -> v:iterator.first() -> v:or(alternative: 0)}">
<v:case case="{v:variable.typoscript(path: 'plugin.tx_mmstemplates.settings.campaignsRootCategoryUid')}" break="TRUE">
<f:render partial="News/Detail/Campaign" section="Main" arguments="{_all}" />
</v:case>
<v:case case="default">
<f:render partial="News/Detail/Default" section="Main" arguments="{_all}" />
</v:case>
</v:switch>
</f:if>
</f:section>
view raw Detail.html hosted with ❤ by GitHub