TYPO3 TypoScript Code Snippets

How do I configure TYPO3 for localized websites?

  1. Website Language Creation
    1. On the TYPO3 Global page via List mode, add a new Website Language. Take note of the uid of that language. To do so, hover over the Website Language icon after saving and closing to see the uid. You'll need this for the sys_language_uid setting later on.
  2. TypoScript Localization by URL or L Parameter
    1. If you do not have the cbstarter extension installed, put Section A into your main website TypoScript template Setup area. Otherwise, put Section A into your main website TypoScript template Constants area.
    2. Put Section B into your main website TypoScript template Setup area, below Section A.
    3. Based upon the URLs or domain names specific to your website and website languages, edit the Section A and Section B config.baseURL and sys_language_uid entries.
    4. config.locale_all
      1. Configures the locale which influences how some values from PHP is formated in the output, eg. dates formatted using strftime() which will then output month/day names in that language.
      2. Refer to the ICU User guide to format the locale_all entry.
      3. Refer to the ISO 639-2 Code List for the language code.
      4. Refer to ISO 3166 for the country code.
    5. config.language
      1. Configures the system “language key” to be used for the language. This is used to select labels from llXML (locallang-XML) files. Setting this should make frontend plugins respond by showing labels from the correct language (requires installation of the corresponding language packs).
    6. config.htmlTag_langKey
      1. Changes "xml:lang" and "lang" attributes in the <html> element.
  3. UTF-8 Configuration
    1. If you do not have extension cbstarter installed, put Section C into your main website TypoScript template Setup area. Otherwise, put Section C into your main website TypoScript template Constants area.
    2. Put Section D into your typo3conf/localconf.php file.
  4. RealURL Configuration
    1. Edit your realurl configuration to include a preVars > getVars > L entry.
    2. See Section E for a sample.
  5. Click "Clear all caches" for your TYPO3 installation.
  6. Create localized content
    1. Basic process
      1. Create alternative page language record
      2. Via Web > Page (TemplaVoila), click the "Create localized version" link on each content element you desire localization of.
      3. Via Web > Page, click the create new content icon, and set the language drop-down.
    2. Refer to the references for creating content in detail.


Section A - TypoScript Localization by URL

config.baseURL = www.cannonbose.com

# SSL is for cannonbose.com
[globalString = _SERVER|HTTPS=on]
config.baseURL = www.cannonbose.com
[end]

Section B - TypoScript Localization by URL or L Parameter

config {
linkVars = L
uniqueLinkVars = L
sys_language_mode = content_fallback
sys_language_overlay = 1
sys_language_softMergeIfNotBlank = tt_content:image, tt_content:header

sys_language_uid = 0
locale_all = en_US
language = en
htmlTag_langKey = en-us
}

# French
[globalVar = GP:L = 1]
config.sys_language_uid = 1
config.locale_all = fr_FR
config.language = fr
config.htmlTag_langKey = fr

# Chinese (Simplified)
[globalVar = GP:L = 2] || [globalString = _SERVER|HTTP_HOST= *.cn]
config.sys_language_uid = 2
config.locale_all = zh_CN
config.language = cn
config.htmlTag_langKey = zh-cn
config.baseURL = www.cannonbose.cn

# Chinese (Traditional)
[globalVar = GP:L = 3] || [globalString = _SERVER|HTTP_HOST= *.tw]
config.sys_language_uid = 3
config.locale_all = zh_TW
config.language = tw
config.htmlTag_langKey = zh-tw
config.baseURL = www.cannonbose.com.tw
[end]

Section C - TypoScript UTF-8 Configuration

config.renderCharset = utf-8
config.metaCharset = utf-8

Section D - localconf.php UTF-8 Configuration

$TYPO3_CONF_VARS['BE']['forceCharset'] = 'utf-8';

Section E - realurl.php Sample Configuration

$TYPO3_CONF_VARS['EXTCONF']['realurl']['_DEFAULT']['preVars'] = array(
array(
'GETvar' => 'L',
'valueMap' => array(
// 'english'
'en' => '0',
// 'french'
'fr' => '1',
// chinese simplified
'cn' => '2',
// 'chinese traditional
'tw' => '3',
),
'noMatch' => 'bypass',
),
);

References

TYPO3 Frontend Localization Guide

Multi Language Sites in TYPO3

TYPO3 XHTML

cbrealurl realurl.php

Extensions

cbstarter

cbrealurl

 

How do I insert a page title into a template?

Put the following into your TypoScript template setup section and via TemplaVoila map a content area to your page title location. Don't forget to name the TemplaVoila data object lib.pagetitle.


lib.pagetitle = TEXT
lib.pagetitle.value = {page:title}
lib.pagetitle.insertData = 1

Category: TypoScript
Expert: Michael Cannon (Profile)
to Top
 

How do you clean up sr_freecap captcha?

Try the following in your TypoScript templates Constants section.

plugin.tx_srfreecap.maxWordLength = 5
plugin.tx_srfreecap.backgroundBlur = 0
plugin.tx_srfreecap.imageHeight = 80
plugin.tx_srfreecap.textColor = 0
plugin.tx_srfreecap.morphFactor = 0
plugin.tx_srfreecap.mergeWithBackground = 0
plugin.tx_srfreecap.backgroundMorph = 0
plugin.tx_srfreecap.backgroundType = White with squiggles
Category: TypoScript
Expert: Michael Cannon (Profile)
to Top
 

How do I create 2- or 3-level sub-menu navigation?

 


lib.subMenu = HMENU
lib.subMenu.entryLevel = 1
lib.subMenu.wrap = <ul>|</ul>
lib.subMenu.1 = TMENU
lib.subMenu.1.NO {
wrapItemAndSub = <li>|</li>
ATagTitle.field = description // title
stdWrap.htmlSpecialChars = 1
}
lib.subMenu.1.CUR = 1
lib.subMenu.1.CUR.doNotLinkIt = 1
lib.subMenu.1.CUR.wrapItemAndSub = <li>|</li>
lib.subMenu.1.CUR.stdWrap.htmlSpecialChars = 1
lib.subMenu.2 < lib.subMenu.1
lib.subMenu.2.wrap = <ul>|</ul>
# lib.subMenu.3 < lib.subMenu.2

Reference

Code from Cannonbose's TypoScript template for this website.

Category: TypoScript
Expert: Michael Cannon (Profile)
to Top
 

How do I create breadcrumb navigation?

 


lib.breadcrumb = HMENU
lib.breadcrumb {
includeNotInMenu = 1
special = rootline
1 = TMENU
1 {
NO.linkWrap = | &#187; |*||*| |
NO.ATagTitle.field = description // title
NO.stdWrap.htmlSpecialChars = 1
CUR = 1
CUR.doNotLinkIt = 1
CUR.stdWrap.htmlSpecialChars = 1
}
}

Reference

Code from Cannonbose's TypoScript template for this website.

Category: TypoScript
Expert: Michael Cannon (Profile)
to Top
 

How do I create browse navigation?

 


lib.internalnav = HMENU
lib.internalnav {
special = browse
special {
items = up|prev|next
prev.fields.title = Previous page
up.fields.title = Up a level
next.fields.title = Next page
}
1 = TMENU
1.NO {
linkWrap = | | |*||*||
stdWrap.htmlSpecialChars = 1
}
}
[treeLevel = 1]
lib.internalnav.special {
prev.fields.title = Previous section
next.fields.title = Next section
}
[end]

Reference

Code from Cannonbose's TypoScript template for this website.

Category: TypoScript
Expert: Michael Cannon (Profile)
to Top
 

How do I create in-line navigation to only certain pages?

 

 


lib.headermenu = HMENU
lib.headermenu.special = list
lib.headermenu.special.value = 338, 10
lib.headermenu.wrap = | &#124;
lib.headermenu.1 = TMENU
lib.headermenu.1.NO {
linkWrap = | &#124; |*||*| |
ATagTitle.field = description // title
stdWrap.htmlSpecialChars = 1
}

lib.headermenu.1.CUR = 1
lib.headermenu.1.CUR.doNotLinkIt = 1
lib.headermenu.1.CUR.linkWrap = | &#124; |*||*| |
lib.headermenu.1.CUR.stdWrap.htmlSpecialChars = 1

Reference

Code from Cannonbose's TypoScript template for this website.

Category: TypoScript
Expert: Michael Cannon (Profile)
to Top
 

How do I create section header?

 


lib.sectionheader =  HMENU
lib.sectionheader {
special = rootline
special.range = 1|1
1 = TMENU
1 {
# NO.doNotLinkIt = 1
NO.ATagTitle.field = description // title
NO.stdWrap.htmlSpecialChars = 1
CUR = 1
CUR.doNotLinkIt = 1
CUR.stdWrap.htmlSpecialChars = 1
}
}

 

Reference

Code from Cannonbose's TypoScript template for this website.

Category: TypoScript
Expert: Michael Cannon (Profile)
to Top
 

How do I put a single content element into a template?

 

 


lib.footeraddress = RECORDS
lib.footeraddress.tables = tt_content
lib.footeraddress.source = 257

lib.footerhours = RECORDS
lib.footerhours.tables = tt_content
lib.footerhours.source = 259

lib.footercopyright = RECORDS
lib.footercopyright.tables = tt_content
lib.footercopyright.source = 258

Reference

Code from Cannonbose's TypoScript template for this website.

Category: TypoScript
Expert: Michael Cannon (Profile)
to Top
 

How do I create today's date?

 


lib.date = COA
lib.date {
10 = TEXT
10.data = date:U
10.strftime = %B %e, %Y
}

 

Reference

Code from Cannonbose's TypoScript template for this website.

Category: TypoScript
Expert: Michael Cannon (Profile)
to Top
 

How do I stay using HTTPS?

Put the following code in your TypoScript template in Constants or Setup depending upon how you set config.baseURL in Setup.


config.baseURL = www.cannonbose.com  
[globalString = _SERVER|HTTPS=on]
# SSL is for cannonbose.com
config.baseURL = https://cannonbose.com/
[end]

Reference

Code from Cannonbose's TypoScript template for this website.

 

How do you create print or share article popups?


lib.print_url = TEXT
lib.print_url {
value = Print
typolink {
parameter = 261 640x480:status=1,menubar=1,scrollbars=1,resizable=1,location=1 - Print Story
addQueryString = 1
addQueryString {
method = GET
}
additionalParams = &print=1
}
}

lib.tip_url = TEXT
lib.tip_url {
value = Email
typolink {
parameter = 210 1000x600:status=1,menubar=1,scrollbars=1,resizable=1,location=1 - Email Story
addQueryString = 0
addQueryString {
method = GET
}
additionalParams.cObject = COA
additionalParams.cObject {
# This part generates the "tipUrl" parameter in the
# correct format. (rawUrlEncoded)
10 = COA
10 {
# This part adds the domain (baseUrl) to the link URL
10 = TEXT
10.data = TSFE:baseUrl

# This part creates an URL pointing to the current page
# including all parameters from the query string.
20 = TEXT
20.typolink.parameter.data = page:uid
20.typolink.addQueryString = 1
20.typolink.addQueryString.exclude = id
20.typolink.addQueryString.method = GET
20.typolink.returnLast = url

# Then everything is rawUrlEncoded so it can
# be placed as a single parameter in the link URL
stdWrap.rawUrlEncode = 1
}
# And finally the parameter data is wrapped with the "&tipUrl=" parameter.
wrap = &tipUrl=|
}
}
}

### articleLinks
temp.articleLinks = COA
temp.articleLinks {
### Printlink
10 < lib.print_url

20 = HTML
20.value =

60 < .20

70 < lib.tip_url
80 < .20
}

lib.printLinks < temp.articleLinks

 

Cannonbose is an Official TYPO3 Consultant

TYPO3 Association Supporting MemberCannonbose is an official TYPO3 consultant providing on-call TYPO3 support and on-going TYPO3 website maintenance. We specialize in the development and support of TYPO3 CMS (content management system) websites. Whether you need TYPO3 development, TYPO3 performance tuning, TYPO3 SEO (search engine optimization), TYPO3 support, or TYPO3 training; we have a TYPO3 support agreement to fit your needs. Cannonbose contributes to TYPO3 by supporting TYPO3 marketing and being a corporate member of the TYPO3 Association.

What Our Clients Have to Say

Cannonbose provided a super-responsive transition of our primary web portal from an antiquated CMS into a well structured and functional TYPO3 installation. I'm incredibly pleased with their professionalism and friendly support. I'd recommend them highly to anyone looking for a dependable development partner.
Steve Adams, Topcon Positioning Systems, Inc.

 

Contact Cannonbose for a Free Consultation

Call +1 (800) 559-9773 or email using this form






captcha