Open Graph Tags example for use with Facebook

page.headerData.120 = COA
page.headerData.120 {
10 = TEXT
10 {
typolink.parameter.data = TSFE:id
typolink.forceAbsoluteUrl = 1
typolink.returnLast = url
typolink.additionalParams.cObject = COA
typolink.additionalParams.cObject {
10 = TEXT
10.dataWrap = &tx_ttnews[tt_news]={GP:tx_ttnews|tt_news}
10.if.isTrue.data = GP:tx_ttnews|tt_news
20 = TEXT
20.dataWrap = &tx_ttnews[cat]={GP:tx_ttnews|cat}
20.if.isTrue.data = GP:tx_ttnews|cat
}
wrap = <meta property=”og:url” content=”|”/>
}
20 < page.headerData.1
20 {
wrap = <meta property=”og:title” content=”| {$siteTitle}”/>
}

30 = TEXT
30.value =
30.wrap = <meta property=”og:site_name” content=”|{$siteTitle}”/>

40 = TEXT
40.value = <meta property=”og:description” content=”” />
40.wrap = <meta property=”og:type” content=”website” />|

}

In additions to the above, we can also set the og:image property on a news detail page like given below:
This new updated Code also includes a default image when news has no image.

page.headerData.120.50 = COA
page.headerData.120.50 {
20 = CONTENT
20 {
table = tt_news
select {
pidInList = 18
andWhere = uid={GP:tx_ttnews|tt_news}
andWhere.insertData =1
selectFields = uid,pid,image
}
renderObj = COA
renderObj {
10 = TEXT
10.value =<meta property=”og:image” content=”http://www.mydomain.com/uploads/pics/
20 = TEXT
20 {
field = image
split {
token = ,
max = 1
cObjNum = 1
1.current = 1
}
ifEmpty.cObject = TEXT
ifEmpty.cObject {
value = alt-image.jpg
}

}
30 = TEXT
30.value = ” />
}
}
}

Typoscript snippet for getting parent title, based on selected Templavoila Template Object

 

5 = TEXT
5 {
#first check with tx_templavoila_to
ifEmpty.cObject = TEXT
ifEmpty.cObject {
data = leveltitle:-2
stdWrap.case = upper
if {
value = 34
isInList.data = levelfield:-1, tx_templavoila_to, slide
}
}
#then check with tx_templavoila_next_to
ifEmpty.ifEmpty.cObject < .ifEmpty.cObject
ifEmpty.ifEmpty.cObject = TEXT
ifEmpty.ifEmpty.cObject.if.isInList.data = levelfield:-1, tx_templavoila_next_to, slide

noTrimWrap = || – |
}

Running a SQL Query using TypoScript

Well, after using this feature for quite long time, I though I should post this info:Consider the following Query:

SELECT DISTINCT FROM_UNIXTIME(`datetime`, ‘%Y’) AS `year` FROM tt_news where pid=113 order by datetime limit 1

My main goal was to get the latest year from the tt_news records, that is then going to be pushed to Tesseract filter.

Soln:

20 = CONTENT
20 {
table = tt_news
select {
selectFields = FROM_UNIXTIME(`datetime`, ‘%Y’) AS year
orderBy = datetime desc
pidInList = 113
max = 1
}
renderObj = TEXT
renderObj.field = year
}

Reference: http://typo3.org/documentation/document-library/core-documentation/doc_core_tsref/4.5.0/view/1/5/#id2621093

Conditional menu based on menu page-id

Following code gives a nice way to have a custom content element as sub-menu item for each main menu item

lib.customMenu = HMENU
lib.customMenu {
 1 = TMENU
 1  {
        wrap = |
        NO.allWrap = | 
        NO.stdWrap.htmlSpecialChars = 1
        NO.after.cObject = COA
        NO.after.cObject {           
            20 = CASE
            20 {
               key.field = uid
               default = RECORDS
               default.tables = tt_content
               default.conf.tt_content < tt_content
               default.conf.tt_content.stdWrap.innerWrap >               
               
               14 < .default               
               14.source = {$submenu_element_14}
               
               15 < .default               
               15.source = {$submenu_element_15}
               
               16 < .default               
               16.source = {$submenu_element_16}
               
               17 < .default               
               17.source = {$submenu_element_17}
               
            }            
            
        }
        ACT = 1
        ACT.after.cObject < .NO.after.cObject
        ACT.allWrap = |
        ACT.ATagParams = class="act"
        ACT.stdWrap.htmlSpecialChars = 1

        CUR < .ACT
        CUR.ATagParams = class="cur"
    }
}

This code cannot be used as it is, you will need to make sure the DHTML/JavaScript code for the sub menu items are configured accordingly.

Further References:

  1. [TYPO3-english] conditional menu based on menu page-id
    http://lists.typo3.org/pipermail/typo3-english/2009-November/065557.html
  2. [TYPO3-english] Custom class in tmenu according to uid page
    http://lists.typo3.org/pipermail/typo3-english/2010-February/067336.html

Display Image when both path and file name are in two fields

The following code gives an overview of how to display an IMAGe when 2 fields are involved.
That is one contains the image path “fileadmin/templates/imgs/” and the other field has the image name “mylogo.png”

10 = IMAGE
10 {
file.import {
cObject = COA
cObject {
10 = TEXT
10.data = field:image_path
20 = TEXT
20.data = field:image_name
}
}
}

Hope this helps.