Search code examples
typo3typoscripttypo3-7.6.xtx-newstypo3-8.x

TYPO3: EXT:news different templateLayouts and corresponding TypoScript


I have configured EXT:news with different templateLayouts as shown in https://docs.typo3.org/typo3cms/extensions/news/AdministratorManual/Templates/TemplateSelector/Index.html

Everything works fine.

Now I want to have different TypoScript per templateLayout. I have two different list-types: list-type 98 and list-type 99. You can choose them in flexform and the fluid-templates switches correct.

But how is it possible to have separate typoscripts for list-type 98 and one for list-type 99?

e.g. list-type 98: 5 news per page, list-type 99: 10 news per page.


Solution

  • This is possible with a kind of workaround.

    1st, create the TypoScript:

    plugin.tx_news.settings {
     default {
      setting1 = abc
      list.image.width = 100
      detail.image.width = 123
     }
     type1 {
      setting1 = abcdef
      list.image.width = 200
     }
    }
    

    2nd, adopt the templates

    Instead of the default partial

    <f:render partial="List/Item" arguments="{newsItem: newsItem,settings:settings,iterator:iterator}" />
    

    you can now do this

    # use a f:case if more than 1 templateLayout used
    <f:if condition="{settings.templateLayout}">
     <f:then>
      <f:render partial="List/Item" arguments="{newsItem: newsItem,settings:settings.type1,iterator:iterator}" />
     <f:then>
     <f:else>
      <f:render partial="List/Item" arguments="{newsItem: newsItem,settings:settings.default,iterator:iterator}" />
     </f:else>
    </f:if>
    

    this should now change the settings everywhere within this partial within this one action.


    Drawbacks I currently see:

    • you need to adopt every template
    • I guess it would make sense to something like plugin.tx_news.settings.default < plugin.tx_news.settings to have all default settings available as well.