News-Latest with the TYPO3 Extension „news“ respectively „tx_news“

Who has used the TYPO3 extension tt_news in the last decade, certainly has built some pages with a news-latest preview. After upgrading to TYPO3 8.6 and the new fluid-based extension „news“ it is getting more difficult to realize this feature, since there is no comprehensive instruction in the online manual.The German speaking reader will find a verbal exchange (including scolding) in the TYPO3-forum, that even the developer of the extension couldn’t settle or calm down and the outcome was not a proper manual. Link:  tx_news: Latest Ansicht- Wie? The argument of the developer is, that there is no sense in having „news-latest“, since it is the same like „news-list“ with less items. But the tricky point is, how to implement a new template that will reduce the listed items to the demands of a preview.Since I usually have my news-preview („news-latest“) in the footer of the webpage, the next question was, how to display news with TypoScript and without the news-plugin-module. And then how to choose a different template for this implementation.My examples are in TYPO3 8.6 and with news version 5.3.2:

a. Structure of the Templates

We have 3 levels: Layouts, Templates and Partials.
Inside the templates  is the function, that renders the partials – the final „news-elements“.

The folder structure from the extension is as follows:

Templates->News->List.html
Partials->List->Item.html

The Partial „Item.html“ consist of: date, headline, teaser, text … basically the news-message or news-element.
The Template „List.html“ is including/referring the partials (our news) and renders them.

So what we need to do is to built a new partial-html-file out of  „Item.html“, that we call „ItemLatest.html“, and where we put our DIVs and classes. And second, inside the Template „List.html“ a decision „if-it-is-latest“ then use the partial-file „ItemLatest.html“.

Aside:
The word „template“ is often used with different meanings. In a structure sense it is a part of the following:
Layout = the outer part of a webpage, like header and footer, that never changes
Template = the part that is inside the Layout and can change for different webpages
Partial = you can have multiple partials on one single webpage inside a Template

And the word is used also for a file, that includes the setup and code for each of the above structure elements:
Layout-Template-File
Template-Template-File
Partial-Template-File

b. Copy the Template-Files which comes with the extension

If you want to avoid that your changes of the Template-Files getting overwritten with every update you must copy them into the fileadmin. I use the same folder structure in the fileadmin as TYPO3 regulates for every extension. This makes things easier, since I always know what is where. See also my other blog post: Folder Structure in TYPO3.

The original files are here: typo3conf->ext->news->Resources->Private->Layouts or Partials or Templates

I copy the content to:
fileadmin->Resources->Private->Layouts->NewsLayouts->(here I have what was is in the Layouts-Folder of the extension, not the folder Layouts itself)
fileadmin->Resources->Private->Templates->NewsTemplates->
fileadmin->Resources->Private->Partials->NewsPartials->

To connect to the new template-files you need some TypoScript in your root-TypoScript-setup:
plugin.tx_news {
view {
templateRootPaths >
templateRootPaths {
0 = EXT:news/Resources/Private/Templates/
1 = fileadmin/Resources/Private/Templates/NewsTemplates/
}
partialRootPaths >
partialRootPaths {
0 = EXT:news/Resources/Private/Partials/
1 = fileadmin/Resources/Private/Partials/NewsPartials/
}
layoutRootPaths >
layoutRootPaths {
0 = EXT:news/Resources/Private/Layouts/
1 = fileadmin/Resources/Private/Layouts/NewsLayouts/
}
}
}

c. Changes in the copied Layouts, Templates and Partials

First we duplicate the file: fileadmin->Resources->Private->Partials->NewsPartials->Item.html and make the copy „ItemLatest.html„.
This is your new Partials-File that defines the news in the latest-view. Here you make your changes for DIVs and classes or just delete stuff you don’t need.

Second, you have to put a „if-then“ construction into the Template-File that calls the partials so it knows when to use which partial.

fileadmin->Resources->Private->Templates->NewsTemplates->News->List.html

You have to do it at two places in the code of List.html:

This part is deleted:

<f:for each="{news}" as="newsItem" iteration="iterator">
<f:render partial="List/Item" arguments="{newsItem: newsItem,settings:settings,iterator:iterator}" />
</f:for>

And replaced with this:

<f:for each="{news}" as="newsItem" iteration="iterator">
<f:if condition="{settings.templateLayout} == 9">
<f:then>
<f:render partial="List/ItemLatest" arguments="{newsItem: newsItem,settings:settings,iterator:iterator}" />
</f:then>
<f:else>
<f:render partial="List/Item" arguments="{newsItem: newsItem,settings:settings,iterator:iterator}" />
</f:else>
</f:if>
</f:for>

This part is deleted:

<f:for each="{paginatedNews}" as="newsItem" iteration="iterator">
<f:render partial="List/Item" arguments="{newsItem: newsItem,settings:settings,iterator:iterator}" />
</f:for>

And replaced with this:

<f:for each="{paginatedNews}" as="newsItem" iteration="iterator">
<f:if condition="{settings.templateLayout} == 9">
<f:then>
<f:render partial="List/ItemLatest" arguments="{newsItem: newsItem,settings:settings,iterator:iterator}" />
</f:then>
<f:else>
<f:render partial="List/Item" arguments="{newsItem: newsItem,settings:settings,iterator:iterator}" />
</f:else>
</f:if>
</f:for>

As you can see we created a if-condition in the code, that asks for an argument „settings.templateLayout == 9″ and then goes for the partial: partial=“List/ItemLatest“. Now we have to add a „setting.templateLayout = 9“ to our news element. (The number you can choose, doesn’t have to be „9“.)

d. Creating a news-element with TypoScript

The basic code comes again – with some small changes – from the news extensions documentation:

lib.news = USER
lib.news {
  userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
  extensionName = News
  pluginName = Pi1
  vendorName = GeorgRinger
  switchableControllerActions {
        News {
          1 = list
        }
  }
  settings < plugin.tx_news.settings
  settings {
        //categories = 49
        limit = 2
        detailPid = 11
        overrideFlexformSettingsIfEmpty := addToList(detailPid)
        startingpoint = 18
        templateLayout = 9
  }
}

We put the whole code in a „lib-variable“, so we can use it later in our FLUIDTEMPLATE for the whole webpage.

The last line creates the setting: „templateLayout =9“.

As we can see with „1 = list“, it is a list-template – in List.html we created before the if-condition.

„limit =2“ gives us maximum 2 news, „detailPid“ is the ID of the page with the single-news-view, „startingpoint =18“ is the news storage folder where our news are stored.

The setup of the FLUIDTEMPLATE for the webpage could look something like this:

(You will find many blogs dealing with FLUIDTEMPLATES.)

page.10 = FLUIDTEMPLATE
page.10 {
     template = FILE
     template.file = fileadmin/Resources/Private/Templates/mainTemplate.html
     partialRootPath = fileadmin/Resources/Private/Partials
     layoutRootPath = fileadmin/Resources/Private/Layouts
        variables {
           dceCont < styles.content.get
           txNews < lib.news
           rootlineNav < temp.rootlineNav
           socialNet < temp.socialNet
           metaNav < temp.metaNav
        }
}
 

And then in your template for the whole webpage – so it is displayed in the footer:

<article class="footerNews"><h2 class="outline">The News from tt_news 2 Items</h2><f:format.raw>{txNews}</f:format.raw></article>

 

e. What to do if you want to use a regular news-plugin element

If we want to put the latest news somewhere in the normal content, we must tell the news-content-plugin that it has the setting number 9. Therefore we must give number „9“ a name in the root-page of your TYPO3-page-tree: /right-click on the root page/ edit->Resources->Page TSConfig:

tx_news.templateLayouts {
9 = ItemLatest
}

Now you can select ItemLatest in your news-plugin:

Plugin->Plugin Options->Template->Template Layout

different templates in the news-plugin

Since I have all my TypoScript code in a file, to put TS directly in the root-page is not so flexible, while going from one to the next webpage. If someone has a solution how to do it with simple TS, please leave a note in the comment section.

 

Additional information, added later on

In my TYPO3 master installation and basic layout for all websites, there is, in combination with Dynamic Content Elements, the need to add for every content element – including news – some wrapper-classes and sourrounding DIVs. This code must be inside the template-template-file, since it should not be repeated with every single news-element. In the footer latest-news though this DIVs and classes are disturbing, so there is an additional if-condition that has to go into the template-template-file.

fileadmin->Resources->Private->Templates->NewsTemplates->News->List.html


<f:if condition="{news}">
<f:then>
<f:comment>The wrapper-class only for not-latest</f:comment>
<f:if condition="{settings.templateLayout} != 9">
<div class="news-list-container wrapper clearfix">
<div class="center">
</f:if>
<div class="news-list-all">

A second possiblity would be to call a different list-template (List2.html). Maybe the developer of the news extension can help with this topic, or some easy calling of different templates in combination with different partials.
 
 
If you have any improvements, please leave a comment!

 

Dieser Artikel ist  in Englisch, nicht um Ihnen das Leben schwer zu machen, sondern um den Autoren weltweit etwas zurückzugeben, die mir auch tagtäglich mit ihren Artikeln helfen!

Autor: Thomas Hezel

DCE pass on – how to reuse DCEs in TYPO3

The zazu-TYPO3-concept

Here at zazudesign in Berlin DCEs or Dynamic Content Elements got the main extension, that we use in combination with TYPO3. Since the basic structure of the extension TemplaVoila! was outdated, there was only the not so flexible concept of backend layouts to replace it.

Dynamic Content Elements makes it finally possible to code your own little backend modules, so the later user can easily change content, without interfering with the basic structure of a webpage.

In short: make a template, put variables at the places where the content should be placed and then use TYPO3s internal skills to create backend forms, to fill the variables with content – that’s it. Of course going into detail, there is much more behind it and much more it can do – a key word is here view-helpers.

In times of responsive web development this little modules need their own little intelligence, basically a clear CSS driven behaviour for different screen seizes.  So a developer has to create the input fields, the templates with variables and view-helpers and a bunch of CCS instructions. In other words you have to put a good amount of time and effort in it. In consequence one must find a way to pass on the DCEs from one TYPO3 installation to another. Better not one DCE, but your little collection, that you developed over time and you are ready to reuse in your basic setup, as an easy and proven installation to start from.

Structure makes work faster especially with a content management system

The folders

If you want to find your slider pictures or your TypoScript text files always at the same place, it is essential to use the same folder structure in all your TYPO3 installation. For the zazu-concept I basically took the structure and rules of the TYPO3 extension development and used it in the fileadmin. So experienced developers will already know where to find what:

 

  • fileadmin
    • Configuration
      • TypoScript
        • root.ts
        • news.ts
        • contact.ts
    • Resources
      • Private
        • Layouts
          • main-layout.html
        • Partials
        • Templates
      • Public
        • Downloads
        • Ext
          • Fotorama-4.6.
        • Fonts
        • Icons
        • Images
        • JavaScript
        • Styles
          • all.css
          • normalize.min.css
There are some rules about nomenclature:

a. folders always have a upper case letter at the beginning
b. files always have a lower case letter at the beginning
c. files that you want to be indexed by google (e.g. pictures) use hyphens (e.g. me-myself-and-i.jpg)

There is a big exception in this rules, „fileadmin“ itself and it’s surrounding folders are lower case.

Inside the folders you can have more folders e.g. inside Partials could be a folder with the „Powermail-Partials“, that you take along, and point to it, instead of the partials, what come with the extension and get overwritten with every update. In the Ext-folder I put everything (JavaScript, CSS, unique icons) that comes with jQuery extensions like Fotorama, just to make updates easier. Not so consistent is TYPO3 with singular and plural that gives me confusion from time to time. Usually it is plural like „Layouts“ but with „JavaScript“ it is singular for some reason. If you want to be stringent in your system go for plural.

Inside the „fileadmin“ folder there are two folders that are created by TYPO3, that is „_processed_“ and „_temp_“, if they are missing the install tool will give a warning and will help you to create them.

The folder „uploads“, that is on the same level as „fileadmin“, is also created by TYPO3 and hosts for example icons that you use inside a TYPO3 extension, so this folder also have to come along to your next website.

Steps to do, from a master project to at a new project

  1. create a master installation that has only placeholder content with all your DCEs
  2. update your master installation and all your extensions
  3. empty all caches, go through „Important Actions“ in install tool
  4. download your „fileadmin“ and „uploads“ folders
  5. make a database dump
  6. install TYPO3 on the new webspace for your new project
  7. install your standard extensions (in my case: dce, realurl, powermail, news, sourceopt, metaseo)
  8. overwrite the „fileadmin“ and „uploads“ folders with your folders from the master project
  9. run install tool „Important Actions“
  10. if you stay on the same TYPO3 level and extensions versions , you can import the complete database dump from your master installation
  11. run install tool „Important Actions“ again
  12. do a „DB check“ (button left side bottom in TYPO3)

A clean installation

TYPO3 was going lately through a lot of changes, so sometimes you don’t want to take along some old stuff (wrong relations m:n, NOT Null problems) in your database and prefer to start with a clean setup. In this case you can just use phpMyAdmin to export only the DCE related tables of the database from your master installation and import it in your new project, instead of importing a complete database dump.

The database tables that contain the DCE-information
Export only the DCE-tables
  • open phpMyAdmin (in most cases in the control center of your webspace provider)
  • go to „Export“, choose the option „custom or options“ („angepasst-zeige alle möglichen Optionen an“)
  • mark the tables „tx_dce_domain_model_dce“ and „tx_dce_domain_model_dcefield“
  • if you want you can save your choise as a pattern („Vorlage“)
  • export the tables to a file xxx.sql
DCE export with phpMyAdmin
Import the file
  • go to your new projects database inside phpMyAdmin
  • delete the tables „tx_dce_domain_model_dce“ and „tx_dce_domain_model_dcefield“
  • click „import“ and import your little database dump with the to tables you want to import
  • go to the TYPO3 backend, now you should see all your DCEs in the DCE-menu
What you miss

Now you miss your complete page-tree, that you have to create again, with all sys-folders for news, powermail, backend templates and so on. You also have to adjust your TypoScript to the new page ids and storage folder ids.

What I allways forget

Don’t forget to add the static templates to the root of your page-tree. If you see funny yellow stripes instead of a DCE-output then you didn’t include some static templates. (DCE doesn’t have a own static template but seems to be affected by the others.)

The new template „content element (fluid_syled_content)“ didn’t cover all backend functions of the DCE but I think the developer of DCE, Armin Vieweg, fixed it with one of the last updates (dce 1.4.2). Worst case you can run it together with ccs_styled_content.

CSS and DCE: how to connect specific CSS-blocks to a specific DCE

As mentioned above it is essential that each DCE gets its responsive CSS. The basic concept is to check the size of your browser screen with media queries.

In the template file of the DCE I put a „div“ outside the whole DCE-template and give it a class=“dxx“ with „xx“ for the DCE number of my collection.  2 columns divs start with „2“, 3 columns divs start with „3“.

Then I make my media queries for each DCE!

This seems to be a lot of checking but I couldn’t find any speed difference against having the media queries only ones in the whole CSS-file. Now each CSS instruction starts with „.dxx“ and therefore gives the DCE it’s unique behaviour.

If a DCE should have some different features on a specific page you should add a page count to the body-element (with TypoScript) of your web page and put it at the beginning: #page3 .d22 {background-color: pink;}

Now the CSS can travel directly (copy and paste) with it’s corresponding DCE and be reused in every setup!

Example CSS-code for the DCE with the class=“d22″:

/*DCE 22 - 2 columns text plus image*/
/*======= 320-NO Query === mobile first ======= border 5  = 310 ===*/
.d22 {
margin-bottom: 2em;
}
.d22 img {
width: 100%;
height: auto;
}
.d22 .colLeft {
margin-bottom: 2em;
}
/*======= 480 ========= MEDIA QUERIES ======= border  6 = 460 ===*/
@media only screen and (min-width: 480px) {
}
/*======= 760========= MEDIA QUERIES ======== border 16 = 728 ===*/
@media only screen and (min-width: 760px) {
.d22 .colRight {
float: left;
width: 45.74175824175824%; /*333px/728px*/
}
.d22 .colRight {
margin-left: 8.516483516483516%; /*62px/728px*/
}
}
/*======= 960 ======== MEDIA QUERIES ======== border 22 = 916 ===*/
@media only screen and (min-width: 960px) {
}
/*======= 1254 ======= MEDIA QUERIES ======== border 28 = 1198 ==*/
@media only screen and (min-width: 1254px) {
}
/*======= 2512 ======= MEDIA QUERIES ==== border 151-45 = 2396 ==*/
@media only screen and (min-width: 2512px) {
}
/*END-DCE 22*/

Avoiding to many server requests

At the end I clean up the code from all empty media queries and put it through a minimizer programme. After that I put all CSS (jQurey extensions, normalizer, my-css) together in one file. With TypoScript I enable then compression.

That’s it!

 

Outlook

Armin Vieweg is the developer of the DCEs. As a lonely hero it’s a lot of work to follow all updates of TYPO3 and keep the extension running with the newest TYPO3 versions. So, please don’t forget to donate!

Additional features I would like to have

One concept for the future could be to have the CSS handled directly by the DCE extension. So like the „template-tab“ you also have a „css-tab“ in the backend. DCE could than put all single CSS-parts together in one file that goes in a folder of your choice – even remove empty media queries and minimize the file.  You could then put it in a all-css-file by hand and include that one in your page setup.

The database export of the DCE tables and the import could be handled inside DCE, instead of using phpMyAdmin. „Export all DCE tables to a sql-file“ and „Import DCE tables from a sql-file“ – option: „add to existing DCEs“ and „overwrite existing DCEs“.

May be even exporting single DCE-database-entries and import them – this could be the beginning of a DCE-share-platform with uploaded screen-shots, sql-files and corresponding CSS.

Will see what Armin will comment on this 🙂

 

Dieser Artikel ist  in Englisch, nicht um Ihnen das Leben schwer zu machen, sondern um den Autoren weltweit etwas zurückzugeben, die mir auch tagtäglich mit ihren Artikeln helfen!

 

Autor: