TYPO3 adding section frames.

Below is the way how we can add the section frames by preserving the content element ID. This way works on TYPO3 6.x.

1. In TS template

### FRAMES ###
tt_content.stdWrap.innerWrap.cObject {
100 < tt_content.stdWrap.innerWrap.cObject.default
100.20.10.value = boxclass
}

2. In page TS Config

TCEFORM.tt_content.section_frame {
addItems.100 = My custom box
}

How to set Open Graph (o:g) meta tags using Typoscript.

The open graph meta tags affects the way how our page link looks, when we share it on social media like on Facebook.

Below is the way how we can set og:title, og:type, og:url, og:description and og:image using Typoscript.

page.headerData {
# Add Open Graph meta
1 = COA
1 {
10 = TEXT
10 {
value = {$siteTitle} : {TSFE:page|title}
insertData = 1
dataWrap = <meta property=”og:title” content=”|”>
}
20 = TEXT
20 {
value = article
wrap = <meta property=”og:type” content=”|”>
}
30 = TEXT
30 {
typolink {
parameter.data = tsfe:id
parameter.insertData = 1
useCacheHash = 1
addQueryString = 1
addQueryString.method = get
addQueryString.exclude = id
forceAbsoluteUrl = 1
returnLast = url
}
wrap = <meta property=”og:url” content=”|”>
}
40 = TEXT
40 {
value = {$siteTitle}
wrap = <meta property=”og:site_name” content=”|”>
}
50 = TEXT
50 {
data = page:description
required = 1
stripHtml = 1
wrap = <meta property=”og:description” content=”|”>
}
60 = FILES
60 {
#gets image form media tab of page
references {
table = pages
uid.data = page:uid
fieldName = media
}
renderObj = TEXT
renderObj {
typolink {
parameter.data = file:current:publicUrl
forceAbsoluteUrl = 1
returnLast = url
}
wrap = |,
}
stdWrap {
listNum = 0
# Use logo image if none is available
ifEmpty.cObject = TEXT
ifEmpty.cObject.typolink {
parameter = fileadmin/templates/images/logo.png
forceAbsoluteUrl = 1
returnLast = url
}
wrap = <meta property=”og:image” content=”|”>
}
}
}
}

Typoscript to include IE specific css and js

Here is how we can include css and javascript that targets different Internet explorer versions using typoscript.

page {
includeJS {
iejs = fileadmin/templates/js/ie.js
iejs.allWrap = <!–[if lt IE 9]> | <![endif]–>
iejs.excludeFromConcatenation = 1
}

includeCSS {
iecss = fileadmin/templates/css/ie.css
iecss.allWrap = <!–[if lt IE 9]> | <![endif]–>
iecss.excludeFromConcatenation = 1
}
}

Here I am including css and js for ie version less than 9.

 

TYPO3 custom session handling.

To implement Shopping cart or shopping basket, we need to store the shopping data in session. Here is the way how we can use simple session handling “Service” to implement it in Extbase extensions.

Below is the php code to handle sessions.  The name of the php file will be “SessionHandler.php” and will be under folder EXT:myext/Classes/Domain/Service. We can identify this from namespace.

<?php

namespace TYPO3\Myext\Domain\Service;

class SessionHandler implements \TYPO3\CMS\Core\SingletonInterface {

public function restoreFromSession() {
$sessionData = unserialize($GLOBALS[‘TSFE’]->fe_user->getKey(‘ses’, ‘basket’));
if (mktime() >= $this->getSessionTimeout()) {
$this->cleanUpSession();
return null;
}
$this->setSessionTimeout();
return $sessionData;
}

public function writeToSession($object) {
$sessionData = serialize($object);
$GLOBALS[‘TSFE’]->fe_user->setKey(‘ses’, ‘basket’, $sessionData);
$GLOBALS[‘TSFE’]->fe_user->storeSessionData();
$this->setSessionTimeout();
return $this;
}

public function cleanUpSession() {
$GLOBALS[‘TSFE’]->fe_user->setKey(‘ses’, ‘basket’, NULL);
$GLOBALS[‘TSFE’]->fe_user->setKey(‘ses’, ‘basketLifetime’, NULL);
$GLOBALS[‘TSFE’]->fe_user->storeSessionData();
return $this;
}

public function setSessionTimeout() {
$GLOBALS[‘TSFE’]->fe_user->setKey(‘ses’, ‘basketLifetime’, mktime() + 600);
$GLOBALS[‘TSFE’]->fe_user->storeSessionData();
return $this;
}

public function getSessionTimeout() {
return $GLOBALS[‘TSFE’]->fe_user->getKey(‘ses’, ‘basketLifetime’);
}
}

So how to use these functions on our controllers ?

First we need to inject it in our controller like this

/**
* @var \TYPO3\Myext\Domain\Service\SessionHandler
* @inject
*/
protected $sessionHandler;

Then we can use below code in controller, for various actions on session.

Let us consider the variable “$basket” has the posted data from the forms. To store that data in session “basket”, below code will help.

$this->sessionHandler->writeToSession($basket);

To retrieve that data from session, we can use

$this->sessionHandler->restoreFromSession();

To cleanup the session,

$this->sessionHandler->cleanUpSession();

In the above php code, we can see that, I have set session timeout at 10 mins (600 secs).

If the user is loggedin, that user session timeout will be handled by

$TYPO3_CONF_VARS[“FE”][“lifetime”] = 600