How to enable jQuery with powermail OR How to remove mootools or prototype from powermail, and use jQuery validation

In some cases we may wish to retain one single library throughout our site, so powermail does not have issues if we choose mootools or prototype.
If we prefer jQuery, then we have some issues at present, as powermail does not yet allow us to use jQuery built in.
The future version however seem to include this feature, and we are waiting, untill then this might prove useful.

  • Step 1: Set nothing for the libraryToUse contstant (of course in constants section)
    plugin.powermail.libraryToUse =
  • Step 2: Set up a different template path for the formWrap — This is important, will explain later in Step3!
    To do this I will copy the formwrap.html located in typo3conf/ext/powermail/templates/tmpl_formwrap.html to fileadmin/templates and set following constant.
    plugin.powermail.template.formWrap = fileadmin/templates/tmpl_formwrap.html

    NOTE: You may change template even in setup section, check manual or ext_typoscript_setup.txt for details.

  • Step 3: Remove the validation script from formwrap.html that we copied just now.
    If you look at the tempalte file, you can see folloing JavaScript:

    <script type=”text/javascript”>
    function formCallback(result, form) {
    window.status = “valiation callback for form ‘” + form.id + “‘: result = ” + result;
    }
    var valid = new Validation(‘###POWERMAIL_NAME###’, {immediate : true, onFormValidate : formCallback});
    </script>

    Remove the above completely including <script> tags.

  • Step 4: Remove automatic inclusion of JS files using TypoScript. (IMPORTANT: This must appear in the setup section)
    page.includeJS.file31311 >
    page.headerData.31310 >

There you go, by now you should have disabled the output of all java scripts and inclusion of JS Libraries like mootools or prototype.
Now you are free to use any library you need.

NOTE: By now the default validation methods available in powermail are also disabled. Well we can easily use the jquery form validation!

Disable a TYPO3 extension or removing a hook specified by another extension

In some cases we may need to disable some hooks that are defined by another extension. Say for example in a recent case, I had to disable js_css_optimizer when a typo3 FE editor is logged in. This was necessary as feeditadvanced was not working together with js_css_optimizer.

So the moment I needed the services of feeditadvanced, I had to disable js_css_optimizer, so I added the following code:

unset($GLOBALS[‘TYPO3_CONF_VARS’][‘FE’][‘cssCompressHandler’]);

We have to make sure that we do this at correct stage, for example, if the extension we wanted to disable has already finished it’s execution, then we may not get desired result, so we may have to add another hook that executes much before the hook we wanted to remove.

Disable js_css_optimizer when using feeditadvanced

I recently noticed that the extension feeditadvanced when used alog with js_css_optimizer gives an error stating that a CSS file is missing!

This is probably caused because feeditadvanced did nt take into consideration the css files that are created by the js_css_optimizer.

Normally we do not need js_css_optimizer if we would like to edit content. So added a quick solution that disables the js_css_optimizer when using on feeditadvanced.

You will need to edit the following file:

typo3conf\ext\feeditadvanced\hooks\class.tx_feeditadvanced_pagerenderer.php

Open this and add the following 3 lines of code inside the IF Condition of the function preProcessPageRenderer():

unset($GLOBALS[‘TYPO3_CONF_VARS’][‘FE’][‘cssCompressHandler’]);
unset($GLOBALS[‘TYPO3_CONF_VARS’][‘FE’][‘jsCompressHandler’]);
unset($GLOBALS[‘TYPO3_CONF_VARS’][‘FE’][‘concatenateHandler’]);

Full code for preProcessPageRenderer():

public function preProcessPageRenderer($params, $parentObject) {

if ($parentObject->getConcatenateFiles() && (t3lib_div::_GP(‘eID’) === ‘feeditadvanced’) && $GLOBALS[‘TBE_TEMPLATE’]) {

unset($GLOBALS[‘TYPO3_CONF_VARS’][‘FE’][‘cssCompressHandler’]);
unset($GLOBALS[‘TYPO3_CONF_VARS’][‘FE’][‘jsCompressHandler’]);
unset($GLOBALS[‘TYPO3_CONF_VARS’][‘FE’][‘concatenateHandler’]);

$compressor = t3lib_div::makeInstance(‘t3lib_compressor’);
$cssOptions = array(‘baseDirectories’ => $GLOBALS[‘TBE_TEMPLATE’]->getSkinStylesheetDirectories());
$params[‘cssFiles’] = $compressor->concatenateCssFiles($params[‘cssFiles’], $cssOptions);
}
}

It would have been great if css files created by js_css_optimizer are used within feeditadvanced, unfortunately that is not the case at present.
Till then I hope we may use the above code.

How to include a custom PHP script in TYPO3

This article is covered in detail in the “doc_core_tsref” here:

http://typo3.org/documentation/document-library/references/doc_core_tsref/current/

Check the article “1.12. PHP include scripts” and 1.13. Case story for detailed info.

In short we can easily include a script in two ways.

Both these code must be written in the setup section of a template record.

  1. Using the CONFIG object.
    ex:
    config.includeLibrary = fileadmin/templates/myscript.php
  2. Using the PAGE object.
    ex:
    page.100.file = fileadmin/templates/myscript.php

That should do the trick. Fo more info I suggest that you please refer “doc_core_tsref“.