1

I´m using a Typo3 V9 together with the tx_news extension by G. Ringer. The extension is working very well, there´s only one feature I didn´t found: Having different news categories, I want to style the teasertext in list view different for each category.

So I need a CSS class varying for every category (best would be the UIDs of the category records mapped directly into a css class). How can I accomplish this?

Jan
  • 43
  • 5

1 Answers1

3

get inspired by the partial for the categories (ext:news/Resources/Private/Partials/Category/Items.html):

<f:section name="category-classes">
    <f:for each="{categories}" as="category"> cat-class-{category.uid}</f:for>
</f:section>

and build it into your template (list, detail, ...)

e.g. the list item (ext:news/Resources/Private/Partials/List/Items.html) modify line 8 from

<div class="article articletype-{newsItem.type}{f:if(condition: newsItem.istopnews, then: ' topnews')}" itemscope="itemscope" itemtype="http://schema.org/Article">

to

<div class="article articletype-{newsItem.type}{f:if(condition: newsItem.istopnews, then: ' topnews')}{f:render(section:'category-classes', arguments:'categories:newsItem.categories')}" itemscope="itemscope" itemtype="http://schema.org/Article">
Bernd Wilke πφ
  • 10,390
  • 1
  • 19
  • 38
  • Thanks that helps me a lot! One question: If I don´t want to change the original partial files (which are propably also getting replaced after an update), is there a way to set my custom file (somewhere in directory /fileadmin/layout/tpl/Items.html) for the original Items.html? Where do I set this? – Jan Jan 17 '20 at 05:11
  • you never should change the original files. and you do not need it. TYPO3 has the mechanism of paths to replace single files in the system of layout, template and partials. Have a look in the manual of the extension and you find that you can set additional paths in the typoscript constants (or [immediate](https://stackoverflow.com/questions/28205787/news-3-0-1-custom-templates)), where the files are searched. Though you can place these files below `fileadmin/` it is state of the art to use a site extension, where you hold all your configuration and individualisation. – Bernd Wilke πφ Jan 17 '20 at 06:53