Month: May 2011

jcarousel adds empty item in circular mode

When using the circular mode in jCarousel(wrap : ‘circular’), we used to see a blank item initially, whhich used to get cleared in the next iteration.

i.e. It seemed like jCarousel generally expects at least one extra item, than the width of scroll area.
In our case the width of scroll area was occupied by 3 items then jQuery needs 3+1 news initially.
If width of scroll area is occupied by 4 news, then there must be 5 news minimum.

Now in such situation we must pre-fill some extra items, that has solved the issue.
ex:

/* When there is less than or equal to 3 items,
* the jcarousel shows blank items in the circular mode!
* So we will add some extra items in such case
* */
if( jQuery(‘#jcarousel .slider-ul’).length <= 3 ){
tempHtml = jQuery(‘#jcarousel .slider-ul’).html();
while(jQuery(‘#jcarousel .slider-ul’).length >= 4){
jQuery(‘#jcarousel .slider-ul’).html(tempHtml + tempHtml);
}
}

jQuery(‘#jcarousel .slider-ul’).jcarousel({
scroll : 1,
auto : 5,
wrap : ‘circular’
});

Hope this helps someone.

How to find and change TYPO3 settings.

This is a small reference to give an idea on how to find a TYPO3 setting that can be changed, and how to change it.

Easy:

  1. go to BE
  2. Click the Configuration module in left menu bar
  3. Now use the drop down at the top, and select TYPO3_CONF_VARS.
  4. Search for what you need
  5. Click on the needed title
  6. Now you get a array like this:
    $TYPO3_CONF_VARS[‘EXTCONF’][‘cachecleaner’][‘tables’][‘cache_pages’][‘expireField’] = ‘expires’;
  7. Change this in your extension (in a PHP file) and include this file in ext_localconf.php
    OR Directly write inside ext_localconf.php (well this may not be very clean)

NOTE: The CONFIGURATION Module is like a TREE browser which lists all kind of available configurations available in TYPO3.
So we have endless chance to change and customize almost anything here!

NOTE2: The TYPO3 Configuration Module is also a place where you can see the current configuration that is in use.
This can be used for wide range of debugging, such as:

  1. To analyze if a HOOK/XCLASS has been declared or not
  2. To see if the configuration we specified has been really recognized by TYPO3

ENJOY!

Adding new fields to existing TYPO3 tables at desired location.

NOTE: This post is intended to add a new field to an existing TYPO3 table at any desired position.
Kickstarter is initially used to add the new field, then we will use fthe following trick to add our new field to a desired location.

GOAL: Add new field called company name, after the subheader field for tt_news of type “External URLS”

STEP 1: Look into the ext_tables.php containing the following method of adding new field to TCA Array.

t3lib_div::loadTCA(‘tt_news’);
t3lib_extMgm::addTCAcolumns(‘tt_news’,$tempColumns,1);
t3lib_extMgm::addToAllTCAtypes(‘tt_news’,’tx_ttnews_fieldcompany;;;;1-1-1′);

STEP 2: Replace the above 3 lines as follows:

t3lib_div::loadTCA(‘tt_news’);
t3lib_extMgm::addTCAcolumns(‘tt_news’,$tempColumns,1);
$TCA[‘tt_news’][‘types’][‘2’][‘showitem’] = str_replace(‘short,’, ‘short, tx_ttnews_fieldcompany,’, $TCA[‘tt_news’][‘types’][‘2’][‘showitem’]);

STEP 2: Alternate, using TYPO3 API (Thanks to Oliver for the code):

t3lib_div::loadTCA(‘tt_news’);
t3lib_extMgm::addTCAcolumns(‘tt_news’,$tempColumns,1);
t3lib_extMgm::addToAllTCAtypes(“tt_news”,”tx_ttnews_fieldcompany;;;;1-1-1″, “”, “after:short”);

STEP 3 Clear cahce and check the news record.
That’s it, now clear your TYPO3 config cache, and check the record, the new field is now just after the sub header field in tt_news record of type External URL.

How to utilize a hook defined in a TYPO3 Extension

This article gives a short overview on how to utilize a hook that is generally written in TYPO3 extension. We will use an available to_news hook for this.

Generally TYPO3 and it’s extensions are written to be extended. Hooks are one such mechanism which helps developers to extend features of an extension without modifying/patching the extension itself. Most well known extensions have hooks that are defined to help us easily extend it’s features. In some cases hooks my not be available at all, but we may have an XCLASS that would be of great help if a hook is not present.

NOTE1:
You cannot use a hook if it is not already defined! So we can use XCLASS in such case.

NOTE2:
The steps defined here uses a tt_news hook as an example, however this method would generally work on all extensions that have a hook.

STEP 1: Check which hook to use.

I added some new fields, and I wanted them to be displayed in list/latest and single view templates of news.
I selected the “extraItemMarkerProcessor” hook that seemed to fit this need.

STEP 2: Check the inputs we get and add appropriate function inside out class

The hook in tt_news was defined as follows:

foreach($GLOBALS[‘TYPO3_CONF_VARS’][‘EXTCONF’][‘tt_news’][‘extraItemMarkerHook’] as $_classRef) {

$_procObj = & t3lib_div::getUserObj($_classRef);
$markerArray = $_procObj->extraItemMarkerProcessor($markerArray, $row, $lConf, $this);

}

So all I did was to write a class with this method/function as follows:

class tx_ttnewshooks {

function extraItemMarkerProcessor($markerArray, $row, $lConf, $ttnews){
// MY CODE GOES HERE

return $markerArray;

}

}

STEP 3: Include our hook

It is now time to include our hook, so that tt_news knows that we would like to use this hook.
Here is what I did:

A. Use kickstarter to create your extension’s skeleton, let me call this as “ttnewshooks“.
ex: By adding information etc…
NOTE: Unfortunetely, I will not be covering how to create an extension with kickstarter.

B. Create a new file called ext_localconf.php (if it is not already here)

C
. Add the following code inside this file:

<?php

if (!defined (“TYPO3_MODE”)) die (“Access denied.”);

if (TYPO3_MODE!=’BE’) {
require_once(t3lib_extMgm::extPath(‘ttnewshooks’).’class.ttnewshooks.php’);
}

$TYPO3_CONF_VARS[‘EXTCONF’][‘tt_news’][‘extraItemMarkerHook’][] = ‘tx_ttnewshooks’;

?>

STEP 4: Time to check if things work.
Generally there should not be any issues.
NOTE: Make sure that our new extension is installed, else this will never work!

Further Reference:
http://typo3.org/development/articles/how-to-use-existing-hooks/

How to add a postUserFunc or parseFunc or binding any userFunction in TYPO3

This is one of the easiest thing that just helps us do almost anything with TYPO3 content.

Well, yes, still the basic stuff we need to find out is how to get this done.

Generally you might have seem in extensions that they use stdWrap, and consider you wish to process the content after the stdWrap is applied.

ex:
After generating a menu, after a news text is displayed from tt_news etc…

As with all my posts, I just love to keep thngs short, so I will just explain this with relation to a tt_news example:

Step 1: Find out where you can bind your user function:

I was in need of processing the news content to strip some special characters from word, so this is what I did.

I could also have used the plugin.tt_news.general_stdWrap.postUserFunc, I however did not wish to touch each field, as I only needed some selected fields to be affected.
Thus, on looking into tt_news/pi/class.tx_ttnews.php I found that there is a config I can make use of that is “itemMarkerArrayFunc”.

Step 2 : Write your user function.

NOTE 1:
Write your userFunc within standard PHP tags, and save it in fileadmin, or EXT folder.
ex:

<?php
//code here
?>

NOTE 2:
Makse sure to understand what type of data is available to us, well sometimes it might be an array as in this case.

NOTE 3:
Your function name should start with “user_

NOTE 4:
Your function declaration should have enough arguments, if not you might be in a surprise.
Generally if you are using parseFunc of stdWrap your function may look like this:
ex:

function user_ProcessData($content,$config){

// do something with $content
$modifiedContent = $content . ” This is modifed”;
return $modifiedContent;

}

THE USER FUNCTION
In my case the function looks like this

function user_ProcessData($markerArray, $conf) {

$str = $markerArray[‘###NEWS_CONTENT###’];
$str = str_replace(‘###CUSTOMER###’,’Customer Name’,$str);
$markerArray[‘###NEWS_CONTENT###’] = $str ;
return $markerArray;

}

Step 3: Include this file in typo3
This can be done in several ways, and here is one such method:

# Add the following code to the setup section of your System Template record. ( we will usually have setup and constants here in General Tab )

includeLibs.itemMarkerArrayFunc = EXT:customext_libs/userNewsMarkerProcessFunc.php

# customext_libs
– is the name of an extension

Step 4: Add final config, so that tt_news knows we want to make use of a parseFunc / userFunc

plugin.tt_news.itemMarkerArrayFunc = user_ProcessData

Step 5: This should generally work.
If not please make sure you followed everything as per the above seteps!