1

I want to use a conditional statement for applying a different template to News (tt_news). Currently I use a user function that returns true/false. If the current News has a specific category and works correctly return 1 otherwise return Null.

I followed the official documentation and other sites, so I made the condition

[userFunc = user_isLatin]
 plugin.tt_news.templateFile = fileadmin/templates/plugins/tt_news/latin_detail.html
 page.1010 = TEXT
 page.1010.value = LATIN  
[ELSE]
 plugin.tt_news.templateFile = fileadmin/templates/plugins/tt_news/general_detail.html
 page.1010 = TEXT
 page.1010.value = OTHERS      
[END]

but it always shows OTHERS. I tried the following with variables

temp.catuid = USER
temp.catuid.preUserFunc = user_ttNewsInCat

latin = TEXT
latin.value < temp.catuid

[latin.value = 1]
 ....
[ELSE]
 ....
[END]

but it doesn't work either.

César Dueñas
  • 331
  • 4
  • 18

2 Answers2

0

It works exactly like you tried to do it. This is the cobndition I tested now:

[userFunc = user_isLatin]
 page.10 = TEXT
 page.10.value = LATIN
[ELSE]
 page.10 = TEXT
 page.10.value = OTHERS      
[END]

And this is the implementation of the user function which must be in the AdditionalConfiguration.php or the localcon.php file of your custom extension (I suppose this is what you missed).

function user_isLatin() {
    return TRUE;
}

For more details see the offcial documentation: https://docs.typo3.org/typo3cms/TyposcriptReference/6.2/Conditions/Reference/Index.html#userfunc

Artur Cichosz
  • 1,034
  • 7
  • 18
0

You don't need to use a user_ function in 6.2, you can also use a class. And you don't need to define it in AdditionalConfiguration.php.

TypoScript:

[userFunc = Vendor\ExtName\Condition\TypoScriptCondition::isLatin()]
...
[else]
...
[global]

PHP:

<?php
namespace Vendor\ExtName\Condition;

class TypoScriptCondition
{

    public static function isLatin()
    {
        ...
        return true;
    }
}
Thomas Löffler
  • 5,922
  • 1
  • 14
  • 29
  • Works probably, but it is stil an undocumented feature in 6.2. At least not in this specific scope. True is that in the global scope in all user function use cases namespaces can be used to resolve a user function which is stil a usefull information. – Artur Cichosz Feb 24 '17 at 09:08
  • I did a Pull Request to add this to the documentation of 6.2 and will add it to 7.6, too: https://docs.typo3.org/typo3cms/TyposcriptReference/6.2/Conditions/Reference/#userfunc – Thomas Löffler Feb 24 '17 at 10:50