I use TYPO3 8.7.3 and my own extension.
So far, I was able to use the $GLOBALS['TSFE']->config['config']['language'] variable to switch in extbase to another language.
This is actually not possible.
Is there a new way to switch between languages in the action of a controller?
Important for me to create Mails and PDF throw:
\TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate
BR
Daniel
In your action you can check for sys_language_uid like this:
if ($GLOBALS['TSFE']->sys_language_uid == 0 ) {
// Your English text
} else if ($GLOBALS['TSFE']->sys_language_uid == 1) {
// Your German text
} else {
// Your English text
}
... when language is set via typoscript:
[globalVar = GP:L = 0]
config {
...
sys_language_uid = 0
sys_language_isocode = en
}
[global]
[globalVar = GP:L = 1]
config {
...
sys_language_uid = 1
sys_language_isocode = de
}
[global]
Related
i have a site package extension for my template in Typo3 9.5. Furthermore I have another extension for a specific purpose. Now this extension searches in the ProviderExtension for template files!?!? On my development machine everything works fine. After I have transferred everything to a remote server, this exception occurs on those pages where the plugin of the extension is included. Other pages work.
The Fluid template files enter code here
"/home/.sites/822/site4946398/web/bttemplate/public/typo3conf/ext/amtstafel/Resources/Private/Partials/Navigation/Top.html",
"/home/.sites/822/site4946398/web/bttemplate/public/typo3conf/ext/amtstafel/Resources/Private/Partials/Navigation/Top"
could not be loaded.
Here is the typoscript fom the Site-Template
page = PAGE
page {
config.index_enable = 1
typeNum = 0
shortcutIcon = EXT:btbuerger2/Resources/Public/Icons/favicon.ico
10 = FLUIDTEMPLATE
10 {
templateName = TEXT
templateName {
cObject = TEXT
cObject {
data = pagelayout
required = 1
case = uppercamelcase
split {
token = pagets__
cObjNum = 1
1.current = 1
}
}
ifEmpty = Default
}
templateRootPaths {
0 = EXT:btbuerger2/Resources/Private/Templates/Page/
1 = {$page.fluidtemplate.templateRootPath}
}
partialRootPaths {
0 = EXT:btbuerger2/Resources/Private/Partials/Page/
1 = {$page.fluidtemplate.partialRootPath}
}
layoutRootPaths {
0 = EXT:btbuerger2/Resources/Private/Layouts/Page/
1 = {$page.fluidtemplate.layoutRootPath}
}
...
The extension amtstafel has a static typoscript which is included in the Main-Template. Here templateRootPaths and layoutRootPaths is defined. As mentioned, the Extension was built with Extension-Builder and works fine so long..
plugin.tx_amtstafel_bulletinentry {
view {
templateRootPaths.0 = EXT:{extension.shortExtensionKey}/Resources/Private/Templates/
templateRootPaths.1 = {$plugin.tx_amtstafel_bulletinentry.view.templateRootPath}
layoutRootPaths.0 = EXT:tx_amtstafel/Resources/Private/Layouts/
layoutRootPaths.1 = {$plugin.tx_amtstafel_bulletinentry.view.layoutRootPath}
}
"bttemplate" is the template extension, "amtstafel" is the additional extension.
In the place of .../amtstafe/... there is not need for partials ...
Thank you for help!
Thomas
I suspect that your constant page.fluidtemplate.partialRootPath is set to EXT:amtstafel/Resources/Private/Partials/
This constant is used in your page.10.templateRootPaths.1
I try to overwrite the typoscript of the extension tx_seobasics. In the tx_seobasics setup.txt I have:
plugin.tx_seobasics {
# Building the page title
10 = TEXT
10.data = page:tx_seo_titletag // page:title
10.trim = 1
10.stdWrap.stdWrap.append = TEXT
10.stdWrap.stdWrap.append.data = TSFE:tmpl|sitetitle
10.stdWrap.stdWrap.append.trim = 1
10.stdWrap.stdWrap.append.required = 1
10.stdWrap.stdWrap.append.if.isTrue = {$plugin.tx_seo.titleWrapAppendSiteTitle}
10.stdWrap.stdWrap.append.noTrimWrap = | - ||
10.stdWrap.noTrimWrap = {$plugin.tx_seo.titleWrap}
10.stdWrap.insertData = 1
10.htmlSpecialChars = 1
10.wrap = <title>|</title>
10.append < .5
20 < .10
20.wrap = <meta name="title" content="|" />
}
Now the idea is that I can set the value for 10.stdWrap.stdWrap.append.data individual for each language.
So my first step/test was I add following typoscript in the setup.txt of my own template:
plugin.tx_seobasics.10.stdWrap.stdWrap.append.data = page:title
This works and instead of the sitetitle that is defined in the template I get the pagetitle as sitetitle.
Now I have 2 problems:
SOLVED First problem: Overwrite .data with .value
Instead of a field I want to add a value directly in typoscript, my idea was:
plugin.tx_seobasics.10.stdWrap.stdWrap.append.value = My own text
or
plugin.tx_seobasics.10.stdWrap.stdWrap.append = TEXT
plugin.tx_seobasics.10.stdWrap.stdWrap.append.value = My own text
both options dont overwrite anything and it still takes the .data = TSFE:tmpl|sitetitle.
So how to overwrite .datawith .value?
Second problem: Set the value for each language separately.
My typoscript setup.txt looks like this:
[globalVar = GP:L = 1]
<INCLUDE_TYPOSCRIPT: source="FILE:EXT:my_template/Configuration/TypoScript/setup-ch.txt">
[global]
[globalVar = GP:L = 2]
<INCLUDE_TYPOSCRIPT: source="FILE:EXT:my_template/Configuration/TypoScript/setup-en.txt">
[global]
Edit: I had a mistake in my language files: I was closing 2 brackets } } on the same line. Never thought about it, but typoscript seems to not like that.
I currently have no idea for the language-condition problem but for overwriting the .data you should try to empty the data first:
plugin.tx_seobasics.10.stdWrap.stdWrap.append.data >
plugin.tx_seobasics.10.stdWrap.stdWrap.append.value = My own text
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.
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;
}
}
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
This is "my" ages old language switch that also accounts for tx_news and does not link the language if there is no translation for a page or a news item (that's the function of USERDEF):
temp.lang_nav = HMENU
temp.lang_nav {
special = language
special.value = 0,1
special.normalWhenNoLanguage = 0
wrap = |
1 = TMENU
1 {
NO = 1
NO {
linkWrap = <li>|</li>
stdWrap.override = DE || EN
# Build Typolink ourself
doNotLinkIt = 1
stdWrap.typolink.parameter.data = page:uid
stdWrap.typolink.additionalParams = &L=0 || &L=1
stdWrap.typolink.addQueryString = 1
stdWrap.typolink.addQueryString.exclude = L,id,cHash,no_cache
stdWrap.typolink.addQueryString.method = GET
stdWrap.typolink.useCacheHash = 1
stdWrap.typolink.no_cache = 0
}
// Active language
ACT = 1
ACT < .NO
ACT {
stdWrap.typolink.ATagParams = class="active"
}
// = NO + No translation
USERDEF1 = 1
USERDEF1 < .NO
USERDEF1{
//doNotShowLink = 1
stdWrap.typolink >
}
// = ACT + No translation
USERDEF2 = 1
USERDEF2 < .USERDEF1
}
}
Also, I've used a variant according to https://gist.github.com/michelalbers/fb0c2e04af1d6ff94788 that has a more modern syntax.
A user reported that suddenly the USERDEF state doesn't kick in anymore for untranslated news.
Actually, I can't prove this did work for untranslated news before, but I'm quite sure.
What do you think; a bug? Wrong syntax? USERDEF not for news, just for pages? Or could this have never worked at all?
If the last, is there a way to achieve such an effect (don't link to translation for untranslated news)?
Apparently, what I'm asking for is not a feature.
A workaround to prevent users from landing on the global 404 page when using the lang switch on an untranslated item would be to make a separate 404 page for news with a clearer explanation.
If you have set something like
'pageNotFound_handling' => 'USER_FUNCTION:typo3conf/ext/template/Classes/Various/noAccess.php:noAccess->pageNotFound',
in localconf, you can do that work there.
i want to add the language id in a typolink
so far
LOGO = COA
LOGO {
10 = TEXT
10 {
value = logo
typolink {
parameter = 116
additionalParams = &L={$config.sys_language_uid}
}
}
}
if L=4 it's working
but if i use L={$config.sys_language_uid} it gets ignored altogether
same with L=GP:L
and L=GPvar:L
what would be the proper syntax here
working if i do something like
additionalParams = COA
additionalParams {
10 = TEXT
10.data = GP : L
10.intval = 1
10.wrap = &L=|
}
You do not need to do that on your own. With the following global TypoScript configuration the parameter L will added to every link:
config.linkVars = L(int)
So, if you use HMENU.special = language this will be managed on the switch automatically, too:)
http://docs.typo3.org/typo3cms/TyposcriptReference/Setup/Config/Index.html
I do not know about {$config.sys_language_uid}, but your code will output it as plain text. In order to use variables like {GP:L}, you got to dataWrap it or insert "insertData" after the value.
10 = TEXT
10 {
value = logo
typolink {
parameter = 116
additionalParams.dataWrap = &L={GP:L}
}
}
OR (the best way I'd say):
10 = TEXT
10 {
value = logo
typolink {
parameter = 116
additionalParams.cObject = TEXT
additionalParams.cObject {
wrap = &L=|
data = GP:L
}
}
}
Using {TSFE:sys_language_uid} might be a better option if you are querying the database.
There is no need to make a cObject or COA
additionalParams = type=0&L={GP:L}
additionalParams.insertData = 1
You can do this kind of URL using addQueryString = 1. https://docs.typo3.org/typo3cms/TyposcriptReference/Functions/Typolink/Index.html#addquerystring