是否可以在TYPO3 Fluid模板中获取当前语言键(或代码)?
与此同时,我发现了另一种使用此处的视图助手的解决方案:
<?php
class Tx_AboUnitReservation_ViewHelpers_LanguageViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractViewHelper {
/**
* Get the current language
*/
protected function getLanguage() {
if (TYPO3_MODE === 'FE') {
if (isset($GLOBALS['TSFE']->config['config']['language'])) {
return $GLOBALS['TSFE']->config['config']['language'];
}
} elseif (strlen($GLOBALS['BE_USER']->uc['lang']) > 0) {
return $GLOBALS['BE_USER']->uc['lang'];
}
return 'en'; //default
}
/**
* Return current language
* @return string
*/
public function render() {
return $this->getLanguage();
}
}
?>
Run Code Online (Sandbox Code Playgroud)
我在流体模板中使用如下.
<f:alias map="{isGerman: 'de'}">
<f:if condition="{aboUnitReservation:language()} == {isGerman}">
<script type="text/javascript" src="{f:uri.resource(path:'js/jquery.ui.datepicker-de-CH.js')}"></script>
</f:if>
</f:alias>
Run Code Online (Sandbox Code Playgroud)
bie*_*ior 12
您可以在操作中指定变量:
$this->view->assign("sysLanguageUid", $GLOBALS['TSFE']->sys_language_uid);
Run Code Online (Sandbox Code Playgroud)
然后在你的视图中阅读:
<f:if condition="{sysLanguageUid} == 0">
You're reading English version of page
</f:if>
Run Code Online (Sandbox Code Playgroud)
另一方面,在控制器中分配redy-to-use变量会更容易,更舒适,因为<f:if ...>块非常简单,有时只是不舒服:
switch ($GLOBALS['TSFE']->sys_language_uid) {
case 1:
$msg = "Bienvenidos";
break;
case 2:
$msg = "Willkommen";
break;
default:
$msg = "Welcome";
break;
}
$this->view->assign("myMessage", $msg);
Run Code Online (Sandbox Code Playgroud)
小智 12
在Fluid模板中使用TypoScript对象的另一种解决方案:
# German language
temp.language = TEXT
temp.language.value = at
# English language
[globalVar = GP:L = 1]
temp.language.value = en
[global]
lib.language < temp.language
Run Code Online (Sandbox Code Playgroud)
和流体代码:
<f:if condition="{f:cObject(typoscriptObjectPath: 'lib.language')} == 'at'">
<f:then>
...
</f:then>
<f:else>
...
</f:else>
</f:if>
Run Code Online (Sandbox Code Playgroud)
temp.language当然,对象可以包含任何值.
为了获得当前的语言,您可以使用VHS扩展中包含的Page/LanguageViewHelper.
{v:page.language(languages: 'en,fr', pageUid: '0', normalWhenNoLanguage: 'en')}
Run Code Online (Sandbox Code Playgroud)
看看这里:http://fluidtypo3.org/viewhelpers/vhs/1.8.3/Page/LanguageViewHelper.html
我的解决方案是这样的:
数据 = TSFE:sys_language_uid
(输出是语言 UID)
page = PAGE
page {
## Fluid-Template ##
10 = FLUIDTEMPLATE
10 {
## Variablen ##
variables {
pageTitle = TEXT
pageTitle.data = page:title
siteTitle = TEXT
siteTitle.data = TSFE:tmpl|setup|sitetitle
rootPage = TEXT
rootPage.data = leveluid:0
baseurl = TEXT
baseurl.value = {$config.domain}
pageLanguage = TEXT
pageLanguage.data = TSFE:sys_language_uid
}
## Settings ##
settings {
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在您可以在 FLUID 中使用新的“变量”:
<f:if condition="{pageLanguage}==0">
<f:then><a href="http://domain.cc/" title="">DE</a></f:then>
<f:else><a href="http://domain.cc/en/" title="">EN</a></f:else>
</f:if>
Run Code Online (Sandbox Code Playgroud)
或者您将其用于更多语言代码:
<f:if condition="{pageLanguage}==0">
<f:then>Do this</f:then>
<f:else if="{pageLanguage}==1">
Do this instead if variable two evals true
</f:else>
<f:else if="{pageLanguage}==2">
Or do this if variable three evals true
</f:else>
<f:else>
Or do this if nothing above is true
</f:else>
</f:if>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
29493 次 |
| 最近记录: |