Archive for the ‘Typo3’ Category

TemplaVoila in your own extension

Thursday, May 15th, 2008

TemplaVoila is an incredibly smart tool for templating your TYPO3 website. However it cannot only be used for pages and fragments of pages (FCE:s), but also for templating your own extensions output.

The classic way of adding template support for an extension has been to use an HTML file marked with tags like

  1. ###MY_REPLACED_MARKER###

or similar that would be replaced by content using the cObj function substituteMarkerArrayCached:

  1. $markerArray[‘###MY_REPLACED_MARKER###’] = $data;
  2. $output =  $this->cObj->substituteMarkerArrayCached($template, $markerArray);

Which is a quite simple and easy to use approach. The TemplaVoila way quite similiar. Let me show you a short example more or less cut from the mininews extension with a few simplifications for us mere mortals;

First off we will load up TV with a hard coded TO (Template Object) record uid. I suggest using some kind of FlexForm setting or similar for that ;) This part normally goes into an init() function or so;

  1. // Load and initialize TemplaVoila TO (if any)
  2. if (t3lib_extMgm::isLoaded(‘templavoila’))    {
  3.   $field_templateObject = 1;  //read my default page "TO" record uid..
  4.   if (intval($field_templateObject))    {
  5.     $this->TMPLobj = t3lib_div::makeInstance(‘tx_templavoila_htmlmarkup’);
  6.     $this->TA = $this->TMPLobj->getTemplateArrayForTO(intval($field_templateObject));
  7.     if (is_array($this->TA))    {
  8.       $this->TMPLobj->setHeaderBodyParts($this->TMPLobj->tDat[‘MappingInfo_head’],$this->TMPLobj->tDat[‘MappingData_head_cached’]);
  9.     }
  10.   }
  11. }

What the code above does is checking if TV exists, instantiates the templavoila HTML markup utility class (tx_templavoila_htmlmarkup), loads a TO record with uid one into it and finally sets some HTML header taggings..

Sooo, we got ourself a loaded TO with HTML template contents and also since TO always has a DS, we got the data structure fields (like field_mainMenu or similar). Next of is adding contents to where we’d like to have it. In our case into the field field_content mapped with TV.

  1. //we got some content into $content var loaded from db earlier, now render it with TV
  2. if (is_array($this->TA))    {    // TemplaVoila:
  3.   // Create list of elements:
  4.   $templatedResult = $this->TMPLobj->mergeDataArrayToTemplateArray(
  5.     $this->TA,
  6.     array(
  7.       ‘field_content’ => $content
  8.     )
  9.   );
  10. }
  11. $out = $templatedResult;

That’s it! :)

Using TemplaVoila for an extension has many benifits, just as using it for normal page rendering. One of them is the possibility to easily map your template using Templavoila. I suggest that you supply a valid datastructure (DS) xml with your extension, that gets loaded as static ds (again taken from mininews);

  1. // Adding datastructure for Mininews:
  2. $GLOBALS[‘TBE_MODULES_EXT’][‘xMOD_tx_templavoila_cm1′][‘staticDataStructures’][]=array(
  3.   ‘title’ => ‘Mininews Template’,
  4.   ‘path’ => ‘EXT:’.$_EXTKEY.‘/template_datastructure.xml’,
  5.   ‘icon’ => ,
  6.   ‘scope’ => 0,
  7. );

For a more detailed documentation around TV and the source to inspiration for this article, see the TemplaVoila extension documentation (http://typo3.org/documentation/document-library/extension-manuals/templavoila/1.3.4/view/1/6/)

jEdit with typoscript syntax highlighting

Tuesday, May 13th, 2008

A short tip; If you’d like to have syntax highlight for your TypoScript code in jEdit on *.txt files (apart from *.ts),  then you would first install the TypoScript plugin, and then set (for instance) “First line glob” field under Global options to

//TSFILE

and type the same on the first line in you ts file. The next time you open it, it will highlight your code.  Simple and effective.

TYPO3 to be TYPO4!

Tuesday, April 1st, 2008

http://bugs.typo3.org/view.php?id=7982

Due to common confusion of TYPO3 and it’s current version it’s now set to be renamed to TYPO4.

That was a really funny April’s first joke (my kind of humor at least)  :D

TYPO3 extension sql difference annoyance when updating

Thursday, March 27th, 2008

When developing extensions for TYPO3 you often create one or more new tables and/or fields. Quite often you get an annoying report when updating or installing your extension in the EM that says something like:

  • ALTER TABLE tx_tentipifr_fieldText CHANGE field_uid field_uid int(11) NOT NULL;
    or
  • ALTER TABLE tx_tentipifr_fieldText DROP KEY parent;
  • ALTER TABLE tx_tentipifr_fieldText ADD KEY parent (pid);

TYPO3 TER manager field updates

while the fields are actually just fine and untouched in your db since last update.
This is because the EM is quite strict to how your ext_tables.sql is formatted. Here is a solution to get rid of the two cases above (example from my ext_tables.sql file):

change

  1. ..
  2. field_uid int(11) NOT NULL,
  3. linksource blob NOT NULLPRIMARY KEY (uid),
  4. KEY parent  (pid),
  5. KEY t3ver_oid (t3ver_oid,t3ver_wsid)
  6. );

to

  1. field_uid int(11) DEFAULT ’0′ NOT NULL,
  2. linksource blob NOT NULLPRIMARY KEY (uid),
  3. KEY parent (pid),
  4. KEY t3ver_oid (t3ver_oid,t3ver_wsid)
  5. );

The integer field notice is fixed by adding DEFAULT ’0′ to the statement and the primary key drop ‘n add thing is fixed solely by removing an extra space right after the field name.

I think these or similar things are fixed or to-be-fixed, but I’m not sure. Just didn’t care to google it. Please let me know if it is so.

TYPO3 and xajax quick guide

Tuesday, November 20th, 2007

Ajax is definetly the thing to go with the web as it enhance the user experience as well as allowing more logic to be on the server side (okey, your pages javascript usualy tend to get slightly more bloated as well..).

Anyway. It’s not ajax in general today, but the good looking PHP/ajax combination found with the xajax project. Xajax allows you to have PHP functions that you mapp/register as javascript calls. There is an extension for TYPO3 called – xajax! You guessed it! There are two tutorial/example extensions as well that describes how it works. But for my memory I’m writing a short guide here as well with my own words. Maybe it helps someone else.

Using ajax in your backend module:

  • Do the obvious. Install the xajax extension from TER (ie TYPO3 Extension Repository).
  • Launch your favourite editor and open your module file like – /typo3conf/ext/myext/mod1/index.php
  • Include the ajax class
  1. // DEFAULT initialization of a module [BEGIN]unset($MCONF);require_once(‘conf.php’);require_once($BACK_PATH.’init.php’);
  2. require_once($BACK_PATH.‘template.php’);
  3. // include XAJAX class library
  4. require (t3lib_extMgm::extPath(‘xajax’) . ‘class.tx_xajax.php’);
  5. $LANG->includeLLFile(‘EXT:myext/mod1/locallang.xml’);
  • Somewhere in your init() method register your PHP function
  1. $this->xajax->registerFunction(array(‘xajaxTest’, &$this, ‘xajaxTest’));
  • In your printContent() method add this to ensure that xajax does whatever it wants (ie handle requests..) first
  1. $this->xajax->processRequests();
  • Then create your nifty PHP function where you want to do magic, and add a responce object like this:
  1. function xajaxTest() {
  2. $c = "ohlas!";// Instantiate the tx_xajax_response object
  3. $objResponse = new tx_xajax_response();
  4. $objResponse->addAssign("mydiv","innerHTML", $c);//return the XML response generated by the tx_xajax_response object
  5. return $objResponse->getXML();
  6. }
  • Now finally add a call to your function. This is probably done in moduleContent() or referenced functions
  1. <a href="#" onClick="xajax_xajaxTest();">xajax magic</a>

Note that we got an extra xajax_ added to the beginning of our function which is added automatically.

That’s it folks!

ignore localization of images for text w/image in TYPO3

Wednesday, October 3rd, 2007

A short one. TYPO3 is amazing when (amongst other things) it comes to localization of website contents. The documentation is quite good to around the subject, which is quite rare when it comes to TYPO3 otherwise. However, today I had totaly forgotten how to, or even if it was possible to, only localize the text part for text w/image elements. After some reading I found this great typoscript key

  1. config.sys_language_softMergeIfNotBlank = tt_content:image, tt_content:header

What this actually does when put in you TS template (together with the rest of the localization settings) is saying that TYPO3 should softly and nicely merge the image and header fields of a content element if it’s not translated into the other translated materials.

Go TYPO3 I say :)

Modded vc_javascriptslideshow

Friday, June 15th, 2007

I’ve modified the TYPO3 extension vc_javascriptslideshow from ground up. The vc_javascriptslideshow is a javascript/css based slideshow that flips images and I needed to be able to control it fully from TS. That ended up in adding a few extras as well.

The extension now includes

  • added full support for TS configuration
  • added support for multiple slideshows on one page
  • Added settings for border and background for the slideshow (stylesheet settings on a surrounding div)
  • Changed the file rezise to use IMG_RESOURCE instead of custom exec of IM and now use width/height attributes there. This makes it also possible to define w/h as ie 200m or 200c for cropping or relative resize (see the static ts template).
  • added support to (in TS only so far) define a path from where all images should be taken.

TypoScript example setup, included via TV element:

  1.  
  2. lib.topBanner < plugin.tx_vcjavascriptslideshow_pi1
  3.  
  4. lib.topBanner {
  5.   //specify path from where to fetch images
  6.   imagesPath = fileadmin/bilder/banners/
  7.   //..or a use a specified list of images
  8.   //  imagesList = Vinter.jpg,Solnedgang.jpg
  9.   altText = informationsruta
  10.     imageWidth = 500
  11.   imageHeight = 70c
  12.   //override imagesList to fetch all images
  13.   getAllFromPath = 1
  14.   //number of millisecond for each transition
  15.   msTransitionDelay = 140
  16.   //background color for slider space
  17.   #backgroundColor = #ccc
  18.   //a possible border if you like
  19.   borderSize = 0
  20. }
  21.  

The extension probably contains some bugs, but works for my purpose. I will try to add some documentation soon.
I have e-mail the original author hoping that he will include it in the official release. Otherwise I’ll probably add a new ext.. (*hrhr*).

Download the modified ext. (unpack, upload and update ext in EM).

GMENU/GIFBUILDER broke my swedish characters

Thursday, March 8th, 2007

We’ve been working on a site for a customer for some time now based on TYPO3. As the the respect to typographical issues where important we decided to go forth using GMENU and GIFBUILDER for menus and headings. I really like the concept of GIFBUILDER and working with it. Sadly we got problems with non ascii characters like our swedish åäö and such. They where replaced by ugly boxes.

Character Ö is replaced by a box..

So, why on earth did this happend I questioned my self.. and people on #typo3 @ irc.freenode.org.

I ended up with these suggestions/requirements:

  1. Make sure you use utf-8 all the way. Gifbuilder (probably GD/freetype really)
  2. Check that the font you use is unicode
  3. Check configuration for mbstring (or iconv) that gifbuilder uses

I did all this. Utf-8 was a requirement for the project as the site will be on both chinese, swedish and english. The font seemed to be in Unicode as well (as far as I could tell). And mbstring was working like a charm..

It’s importent to mention that the development server was a windows server.

Anyway. I copied the site to my local windows computer and tested it. The same buggy result. The I copied it to my own webserver running on debian linux and there it worked! Why? Donno.. However. I went back to my local computer and replaced the font with arial. I got nifty åäö all the sudden. This at least allowed me to assume that it had something to do with the font file (a .otf file btw). The only solution I could think of now would be to convert the font hopfully to utf-8. I got merely no experience with typographical things so this was a blank area for me, but after som googleing I stumbled upon fontforge (http://fontforge.sf.net). It’s actually a *NIX application but I installed Cygwin (along with xfce4), and the cygwin port of fontforge. Wow what an app! A really crappy gui, but wow! :)

fontforge with cygwin

So, I went on and converted my .otf font forcing it to Full unicode, replaced it in my exsisting font on the site. It worked like a charm!

My final configuration on every aspect turned out like this:

localconf.php:

  1.  
  2. // UTF-8 support
  3. $TYPO3_CONF_VARS[‘GFX’][‘gdlib_2′] = ’1′;
  4. $TYPO3_CONF_VARS[‘BE’][‘forceCharset’] = ‘utf-8′
  5. // For GIFBUILDER support
  6. // Set it to ‘iconv’ or ‘mbstring’
  7. $TYPO3_CONF_VARS[‘SYS’][‘t3lib_cs_convMethod’] = ‘mbstring’;
  8. // For ‘iconv’ support you need PHP 5!
  9. $TYPO3_CONF_VARS[‘SYS’][‘t3lib_cs_utils’] = ‘mbstring’;
  10. // For Asian languages
  11. $TYPO3_CONF_VARS[‘SYS’][‘multiplyDBfieldSize’] = 3;
  12. //force db communication to utf8
  13. $TYPO3_CONF_VARS[‘SYS’][‘setDBinit’] = ‘SET NAMES utf8;’;
  14.  

Typoscript

  1.  
  2.  
  3. ## GIFBUILDER HEADING RENDER SETUP ########
  4. ##
  5. ##### Header 1
  6. cHeader1 = IMAGE
  7. cHeader1 {
  8.     alttext.cObject = TEXT
  9.     alttext.cObject.field = header
  10.     wrap = <div class="h1gfx">|</div>
  11.     file = GIFBUILDER
  12.     file {
  13.         format = gif
  14.         reduceColors = 15
  15.         transparentColor = #ffffff
  16.         XY = [10.w]+2,[10.h]+8
  17.         backColor = #ffffff
  18.         10 = TEXT
  19.         10 {
  20.     text.field = header
  21.     fontSize = 14
  22.     offset = 0,20
  23.     fontColor = #333333
  24.     fontFile = fileadmin/fonts/NewsGothicStd_utffull.ttf
  25.     antiAlias = 1
  26.     value.case = upper
  27.         }
  28.     }
  29. }
  30.  

Database was set to full utf-8 charset in all tables from the beginning.

See http://wiki.typo3.org/index.php/UFT-8_support about utf-8 support for TYPO3.

Change layout of filelinks lists in typo3

Monday, February 19th, 2007

I recently had to change the title of my files in filelinks with typo3. As I’ve become customed with the thought of having mostly either a full or partial solution to every problem with Typo3, I headed off to google and looked for ways to modify the filelinks.

This got me to css_filelinks. A nice way to modify most appearance aspects of filelinks. I think it’s actually a good example of how T3 can be modified by behaviour and function.
Anyway, with that one you can change the FE (FrontEnd) display to your likening with a template/marker styled way. Instead of displaying ###TITLE### (filename) I choosed to use the description field that you can add in the filelinks setting.

  1.  
  2. tt_content.uploads.20.layout.file >
  3. tt_content.uploads.20.layout.file.cObject=COA
  4. tt_content.uploads.20.layout.file.cObject{
  5.   wrap=<div class="filelinkslist">&#124;</div>
  6.   10 = TEXT
  7.   10.wrap=<span>&#124;</span>
  8.   10.value=###ICON###<a href="###URL###">###DESCRIPTION###</a>
  9.   20 <.10
  10.   20.value=###FILESIZE###
  11. }
  12.  

Configuration reference: http://typo3.org/documentation/document-library/extension-manuals/css_filelinks/0.2.11/view/1/3/

Handling localization of database relation fields in a good way..

Monday, December 18th, 2006

With Typo3.
When you use database relation fields in an extension you get problems with localizations as all localized/unlocalized records are selectable for each localization version of your record.

As I couldn’t find anything about this easily when googling (or posting in t3 english newsgroup) I thought it would be valuable to write a few lines about it here.

The first thing I did was, after a tip from someone who I can’t remember gave me the tip to alter the foreign table where clause like this


"foreign_table_where" => "AND sys_language_uid in (-1,0)

in the tca definition (tca.php) of the extension.

This restricts my selection to only do relations against either “all” or “default” language for any translation. However it still leads to data inconsistancy as I don’t want this to be different to each language, but reflected from default language settings. Then I found the l10n_mode for the TCA.

Doing the following hides my field for localized records though still selectable in the default language.


"l10n_mode" => "exclude",

Se the TCA reference[1] table for details.

[1] http://typo3.org/documentation/document-library/core-documentation/doc_core_api/4.0.0/view/4/1/