-1

Using TYPO3 v7.6.13 ext:news 5.3.2

I've created two Detail partials to use on a single page, this is the page TS Config:

tx_news.templateLayouts {
        11 = HomePage Top Banners
        12 = HomePage List
}

Im able to write two conditions so that the appropriate template is used.

<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
    xmlns:n="http://typo3.org/ns/GeorgRinger/News/ViewHelpers"
    data-namespace-typo3-fluid="true">
<f:layout name="General" />
<!--
  =====================
    Templates/News/List.html
-->

<f:section name="content">
  <!--TYPO3SEARCH_end-->
  <f:if condition="{news}">


<f:then>
        <f:if condition="{settings.templateLayout} == 11">
            <f:then>
                    <f:for each="{news}" as="newsItem">
                       <f:render partial="List/homepagetopbanner" arguments="{newsItem: newsItem, settings:settings}"/>
                    </f:for>
            </f:then>
</f:if>


  <f:if condition="{settings.templateLayout} == 12">
    <f:then>
       <f:for each="{news}" as="newsItem">
        <f:render partial="List/homepagelist" arguments="{newsItem: newsItem, settings:settings}"/>
       </f:for>
    </f:then>
    </f:if>

</f:then>



    <f:else>
      <div class="no-news-found">
        <f:translate key="list_nonewsfound" />
      </div>
    </f:else>
  </f:if>
  <!--TYPO3SEARCH_begin-->
</f:section>
</html>

Im struggling with setting a fallback option, so that the default Detail is used if nothing else is selected.

As I understand, you are not able to write else if statements in this case, is there anyway to set a fallback option?

Tom
  • 109
  • 1
  • 15

3 Answers3

0

elseif will be/is only possible in TYPO3 8.

Until then you need to cascade if VHs in else VHs:

<f:if condition="{settings.templateLayout} == 11">
<f:then>
    // do template 11
</f:then>
<f:else>
    <f:if condition="{settings.templateLayout} == 12">
    <f:then>
        // do template 12
    </f:then>
    <f:else>
        // do default-template
    </f:else>
    </f:if>
</f:else>
</f:if>

or you use the switch viewhelper:

<f:switch expression="{settings.templateLayout}">
<f:case value="11">
    // do template 11
</f:case>
<f:case value="12">
    // do template 12
</f:case>
<f:case default="TRUE">
    // do default template
</f:case>
</f:switch>

but that viewhelper has some small drawbacks, so I would prefer the cascaded if VHs.

Bernd Wilke πφ
  • 10,390
  • 1
  • 19
  • 38
0

Elvis, thank you very much.

I experienced some odd behaviour with the template you provided.

When I selected template 11 in the front end, both the template with the id of 11 and the default template rendered each news item.

However, I used the code below and it works fine. I removed the else condition and instead just use three if conditions: 11,12 or default(0).

<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
    xmlns:n="http://typo3.org/ns/GeorgRinger/News/ViewHelpers"
    data-namespace-typo3-fluid="true">
<f:layout name="General" />
<!--
  =====================
    Templates/News/List.html
-->

<f:section name="content">
  <!--TYPO3SEARCH_end-->
  <f:if condition="{news}">
      <f:then>
          <f:if condition="{settings.templateLayout} == 11">
              <f:then>
                <f:for each="{news}" as="newsItem">
                   <f:render partial="List/homepagetopbanner" arguments="{newsItem: newsItem, settings:settings}"/>
                </f:for>
              </f:then>
          </f:if>
          <f:if condition="{settings.templateLayout} == 12">
            <f:then>
               <f:for each="{news}" as="newsItem">
                <f:render partial="List/homepagelist" arguments="{newsItem: newsItem, settings:settings}"/>
               </f:for>
            </f:then>
          </f:if>
      </f:then>
     <!-- THIS IS THE DEFAULT -->
     <f:if condition="{settings.templateLayout} == 0">
               <f:for each="{news}" as="newsItem">
                <f:render partial="List/Item" arguments="{newsItem: newsItem, settings:settings}"/>
               </f:for>
     </f:if>

      <f:else>
        <div class="no-news-found">
          <f:translate key="list_nonewsfound" />
        </div>
      </f:else>
  </f:if>
  <!--TYPO3SEARCH_begin-->
</f:section>
</html>

Hope that makes sense,

Thank you very much for your assistance.

Tom
  • 109
  • 1
  • 15
  • your fluid code is invalid as it contains the f:if for template 0 outside of the f:then and f:else in the surrounding f:if. or another point of view: the of the outer f:if needs to be behind the default f:if. – Bernd Wilke πφ Feb 20 '17 at 14:24
-1

Sure you can use else like in the script below:

<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
    xmlns:n="http://typo3.org/ns/GeorgRinger/News/ViewHelpers"
    data-namespace-typo3-fluid="true">
<f:layout name="General" />
<!--
  =====================
    Templates/News/List.html
-->

<f:section name="content">
  <!--TYPO3SEARCH_end-->
  <f:if condition="{news}">
      <f:then>
          <f:if condition="{settings.templateLayout} == 11">
              <f:then>
                <f:for each="{news}" as="newsItem">
                   <f:render partial="List/homepagetopbanner" arguments="{newsItem: newsItem, settings:settings}"/>
                </f:for>
              </f:then>
          </f:if>
          <f:if condition="{settings.templateLayout} == 12">
            <f:then>
               <f:for each="{news}" as="newsItem">
                <f:render partial="List/homepagelist" arguments="{newsItem: newsItem, settings:settings}"/>
               </f:for>
            </f:then>
            <f:else>
               <f:for each="{news}" as="newsItem">
                <f:render partial="List/default" arguments="{newsItem: newsItem, settings:settings}"/>
               </f:for>
            </f:else>
          </f:if>
      </f:then>
      <f:else>
        <div class="no-news-found">
          <f:translate key="list_nonewsfound" />
        </div>
      </f:else>
  </f:if>
  <!--TYPO3SEARCH_begin-->
</f:section>
</html>

or you can use it with the default template layout which is 0 like this

<f:else condition="{settings.templateLayout} == 0">
  Add your code here ..
</f:else>