Archive

Posts Tagged ‘typoscript’

TYPO3 / tt_news – use news title as page title in multilanguage environment

September 16th, 2011 No comments

If you are using the popular extension “tt_news”, you probably want the news title as page title on the single view of the news entries. Especially for SEO and sharing (Facebook, Twitter,…) it is very useful to have this information in the TITLE – tag of the page.

All you have to do is to overwrite the default page title with the custom news title – but it is tricky if you want this behaviour for all configured languages on your page!

I’ll simply post my typoscript configuration here with some comments – if you have further questions, feel free to post them…


#######################

### first check, if we have a news id in the querystring
[globalVar = GP:tx_ttnews|tt_news > 0]

lib.newstitle = CONTENT
lib.newstitle {
table = tt_news
select {
selectFields = title
languageField = sys_language_uid

# id(s) of the page with the tt_news records

pidInList = 120,121
andWhere {

# grab the querystring vars and assign it to uid

data = GP:tx_ttnews|tt_news
wrap = uid = |
}

# define the language

languageField = sys_language_uid

}
renderObj = COA
renderObj {
10 = TEXT
10.field = title
}
}
[global]

Now we have a typoscript object named “lib.newstitle” containing the title
of the current displayed news entry. But CAUTION: this works for the default language only, if we want additional languages, we have to alter the select statement to use the “l18n_parent” id for the given data item:


[globalVar = GP : L = 1,GP : L = 2, ...]
lib.newstitle.select.andWhere.wrap = l18n_parent = |
[global]

Just insert all you configured language ids.
Finally, we have to assign the “lib.newstitle” string to our page (assuming, that our title is configured in page.headerData.10) :


[globalVar = GP:tx_ttnews|tt_news > 0]
page.headerData.10 >
page.headerData.10 = COA
page.headerData.10 < lib.newstitle
page.headerData.10.wrap =
[global]

That’s it – hopefully, this will save some time for you…

Categories: Programming, Typo3 Tags: , ,

Cropping of images in typo3 with typoscript

June 17th, 2010 4 comments

This posting is based on version 4.3.3 of typo3.

It is often necessary to display thumbnails with fixed width and height values for each image (e.g. some image gallery…), which is a challenge if you have images of different formats (4:3, 16:9,…).

Typo3 offers the “cropping” function, which means the original image is scaled to a given width and height – to preserve the proportions of the image, it automatically resizes the images to match the given values.

E.g. if you want to scale all images in a content element of type “Image” to 160 x 120, you can use the following Typoscript code:


tt_content.image.20 {
1.file.width.field >
1.file.width = 160c
1.file.height = 120c
1.file.width.override.field = imagewidth
1.file.height.override.field = imageheight
}

It is very important to add the postfix “c” (for crop) to the pixel value.

In a concrete project, i had the challenge to render the thumbnails only for certain “Image” elements, not for the whole site. I chose to use the “Frame” (section_frame) property of the content element. So if you want to apply above settings only to content elements, which fit a defined section_frame value, you can use the following Typoscript:

tmp.CONTENT.HEADER.CONTENT < tt_content.image.10
tmp.CONTENT.IMAGE.CONTENT < tt_content.image.20
tt_content.image = CASE
tt_content.image {
key.field = section_frame
# id of the frame
3 = COA
3 {
10 >
10 < tmp.CONTENT.HEADER.CONTENT
20 >
20 < tmp.CONTENT.IMAGE.CONTENT
20 {
# cropping f. gallery
1.file.width.field >
1.file.width = 160c
1.file.height = 120c
1.file.width.override.field = imagewidth
1.file.height.override.field = imageheight
}
}
# rendering for all other frame values
default = COA
default {
10 >
10 < tmp.CONTENT.HEADER.CONTENT
20 >
20 < tmp.CONTENT.IMAGE.CONTENT
}
}
tmp.CONTENT.HEADER.CONTENT >
tmp.CONTENT.IMAGE.CONTENT >

In the above example, the value 3 is the selected value for section_frame. Its important to copy the existing values to the new COA object and then override the needed settings.

I spent some time to find a solution for this specific problem – hopefully this will help somebody to save some time….

Categories: Programming Tags: , ,