Archive

Posts Tagged ‘typo3’

Cropping of images in typo3 with typoscript

June 17th, 2010

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….

admin Programming, Uncategorized , ,

Typo3 (4.2.8), utf-8 encoding and caching

August 31st, 2009

Recently, a weird problem occured in my current typo3 – project. The caching was configured properly (out of the box configuration) and all caching tables were written as they should – but with a very confusing behaviour: the whole page was generated completely new by typo3 on each page request, which caused high server load. The error was not caused by an overriden no_cache-value or one of the other usual suspects (USER_INT, config – directives). After spending days trying to find a fix for the problem, i finally found a solution:

The problem was the configuration of the typo3 – installation, which is set to use utf-8 in the database backend and frontend output. All databse tables were correctly set to utf-8 and the rendering of special chars worked liked a charm – but there seemed to be a missmatch in rendering the page content and generating the cache content. Because of this missmatch, the pages were correctly saved in the table page_cache, but the entry was renewed on every page request. To solve this problem, you have to set the value of the [setDBinit] directive as followed when using utf-8 (either in the typo3 install tool or via localconf.php):


[setDBinit]
SET character_set_client = utf8
SET character_set_results = utf8
SET character_set_connection = utf8


Normally, the value SET NAMES = utf8 should do the trick, but that didn’t work for me. After setting this value and clearing up the whole system cache, your pages should be served from the cache.

For a complete tutorial how to configure typo3 to use utf-8 consistently, take a look at
http://www.typo3-media.com/blog/article/utf8-and-typo3-updated.html
(this tutorial still uses the “SET NAMES” directive, be sure to change it….)

admin Programming , , ,

typo3 – enable admin panel in preview mode for non-admin users / groups

June 18th, 2009

Typo3 offers a nice feature to edit content elements of a page directly in the preview mode – but this functionality is only available for admins per default. In my projects, it’s important for all users to have this feature. As so many tasks in typo3, it is not very obvious how to enable it – so here is a (very short) tutorial, how it works to add it for backend-groups.

First step – default template

In the default template (which is typically the site’s root), you have to enable the admin panel, which is done by the following command in the typoscript- setup:

config.admPanel = 1

Second step – enable and configure the panel for the usergroup

Switch to the user admin, select a user, who is a member of the group to which you want to add the feature, select the assigned group and press the “edit” symbol. The configuration dialogue for the user group pops up – now select the “options” tab and enter the following typoscript:

admPanel {
enable.all = 1
enable.edit = 1
module.edit.forceNoPopup = 0
module.edit.forceDisplayFieldIcons = 1
module.edit.displayIcons = 1
module.edit.forceDisplayIcons = 1
enable.cache = 1
enable.preview = 1
enable.publish = 1
enable.tsdebug = 1
enable.info = 1
hide = 0
}

This is just an example setting, please refer to the typoscript reference for a complete list of options. After saving, you can switch to an user who is a member of the group, select a page in preview mode – voila  – now you should see a panel where you can move, edit, hide and delete content elements.
If you do not use groups, you can simply set the above typoscript to a single user – but using groups always makes sense.

I hope this saves some time for someone who runs into a similar issue. Thankyou, Rüdiger!

admin Programming , ,