By Sebastiaan de Jonge, published on Wednesday, December 22, 2010 at 11:00

Sometimes I wonder how far you can actually go in using just TypoScript to achieve your technical challenges. Today I will show how you create a simple page teaser with multilingual support by just using some TypoScript.

#A
temp.pageTeasers = CONTENT
temp.pageTeasers {
  table = pages
  pidInList = this
  orderBy = sorting ASC
  #B
  renderObj = COA
  renderObj {
    10 = COA
    10 {
      10 = TEXT
      10.typolink.parameter.field = uid
     }
    10.stdWrap.stripHtml = 1
    10.stdWrap.outerWrap = <h3>|</h3>
    #C
    20 = CONTENT
    20 {
      table = tt_content
      select {
        pidInList.field = uid
        andWhere.wrap = bodytext != '' AND deleted != 1 sys_language_uid=|
        andWhere.data = TSFE:sys_language_uid
        andWhere.intval = 1
        orderBy = sorting ASC
        max = 1
      }
      #D
      renderObj = COA
      renderObj {
        10 = HTML
        10.value {
          field = bodytext
          cropHTML = 150|...
          parseFunc < lib.parseFunc_RTE
        }
      }
    }
    #E
    15 = IMAGE
    15 {
      file {
        import = uploads/media/
        import.field = media
        import.listNum = last
        height = 75c
        width = 100c
      }
    }
    #F
    30 = TEXT
    30 {
      value = More information
      lang {
        de = Mehr Information
        fr = Plus d'informations
        nl = Meer informatie
        es = Más información
        it = Maggiori informazioni
      }
      typolink {
        parameter.field = uid
        additionalParams.dataWrap = &L={TSFE:sys_language_uid}
      }
      outerWrap = <span class="more-info">|</span>
  }
  wrap = <div class="my-typoscript-page-teasers">|</div>
}

The explanation

To make it easier, I've added some comments (marked as #A, #B etc) to show what goes on where.

#A: We start with creating a CONTENT object, which we will fill with all the subpages of the current page. 

#B: Inside the renderObj we will define what is displayed: where, when and how.

#C: The COA inside the renderObj is used in a clever way to get the translated page titile. This is explained in my previous post.

#D: Our next CONTENT object will be used to display the first content element (that has a bodytext) from the current supage, on the default column. We use lib.parseFunc_RTE in order to display RTE text properly. And as you see I have cropped the text down to 150 characters with the cropHtml function, so we won't break any HTML tags.

#E: To add a little fun to the teaser, I will now add an image as well. Which I will grab from the media field on the last page. Since on the page where I used this, the header image is stored in the media field of the subpage as well. So I used listNum = last in order to get the last image as preview for the page.

#F: And finally, to give an extra demonstration of the multilingual capabilities, I will display a 'read more' link in the appropriate language.

Comments

Sebastiaan de Jonge
Sebastiaan de Jonge - Thursday, May 3, 2012 at 09:22

Hi Andrey,

Sorry for the late reply here 🙂

This function fetches the first content element found on the page. You might have to apply a more specific filter on the #C section to get the content you want.

Cheers,Sebastiaan

Andrey
Andrey - Tuesday, March 6, 2012 at 19:43

Hi! Thank you for this script, but i have a problem - 'bodytext' isn't working... All teasers has title and Read More link, but no bodytext....

Mario Colombo
Mario Colombo - Sunday, April 27, 2014 at 12:26

I am using this concept to generate an XML feed for a page (and its subpages) in typoscript only.

If somebody is interested in this solution I am happy to help.

Something I haven't solved yet is how to get the image content elements out of FAL (in Typo3 >6.0). If somebody has a solution please share. Thanks in advance, Mario