By Sebastiaan de Jonge, published on Tuesday, December 21, 2010 at 20:00

This is something really cool I had to create recently for one of my projects. I actually had to create a page teaser, which due to the simplicity of the teaser I decided to do with TypoScript (I will show how to make the teaser in the next post). First I will show how you can get the translated page title without creating any weird constructions.

temp.pageTeasers = CONTENT
temp.pageTeasers {
  table = pages
  pidInList = this
  orderBy = sorting ASC
  renderObj = COA
  renderObj {
    10 = COA
    10 {
      10 = TEXT
      10.typolink.parameter.field = uid
    }
    10.stdWrap.stripHtml = 1
    10.stdWrap.outerWrap = <h3>|</h3>
  }
}

How it works

If you take a look at the code you will see that first we create a CONTENT object. In this we load the subpages of the current page we are on. In the renderObj of that object we are going to display the page title. By default setting renderObj.10.value.field = title will display the title of the default language.

Since pages use overlays for translations, this would mean that in theory we will need to get the overlay for each page manually. Since this is not done with our previous request. There's a quick and clever trick to avoid this.

We can generate a typolink and leave the value of renderObj.10.value empty in order to get the right title, but by doing so we will also automatically link to the page. In the case that we don't want that link, we can do another little trick.

As you see I've put the typolink inside another COA. This way I can use an stdWrap function on that COA to clear the HTML tags that are generated by the child objects' typolink function. Thus generating a clean translated page title as output.

It may seem a little like a dirty trick, since the link needs to be generated first while it's not needed. But in the end I think it's a good solution for the problem.

Comments