I would like implement multilingual labels in TYPO3 mask. After implementing with the following FLUID-code the label does not change based on the chosen language:
<f:link.page pageUid="{data.tx_mask_inhalt_text_link}">
<f:if condition="{TSFE.sys_language_uid} == 1">
<f:then>
enter code here`Read more
</f:then>
<f:else>
Weiterlesen
</f:else>
</f:if>
</f:link.page>
I solved the issue with:
MASK-Template:
<f:translate key="label" />
TYPO3-Setup:
plugin.tx_mask._LOCAL_LANG.de.label = Weiterlesen
plugin.tx_mask._LOCAL_LANG.en.label = Read more
Works like a charm.
You can use XLIFF files to localize values in TYPO3. This is neither limited to nor different for mask templates (as these are common Fluid templates).
A locallang.xlf contains entries like:
<trans-unit id="readmore">
<source>Read more</source>
<target>weiterlesen</target>
</trans-unit>
In the HTML template you can use the f:translate viewhelper:
<f:translate key="LLL:EXT:your_extension/Resources/Private/Language/locallang.xlf:readmore" />
This will render the value depending on the current frontend language.
This is the usual way of translating in TYPO3. Please refer to these official documentations for all details:
XLIFF | TYPO3 documentation
f:translate | Fluid guide
Related
I have an array ('db-titles') whose items are strings composed in the form 'TextA*TextB'.
I want to create the following HTML structure from these array items: <span>TextA</span><span>TextB</span>
For this I use the following fluid script:
{namespace v=FluidTYPO3\Vhs\ViewHelpers}
<f:if condition="{db-titles -> f:count()} > 1">
<f:then>
<!-- This works as expected, the html code will be rendered correctly -->
<v:iterator.for from="0" to="{db-titles -> f:count()}" iteration="i">
<span><v:format.replace content="{db-titles.{i.index}}" substring="*" replacement="</span><span>"/></span>
</v:iterator.for>
</f:then>
<f:else>
<!-- This strangely does not work, although I - instead of running through all values of the array - just want to output the first value of it.... -->
<span><v:format.replace content="{v:iterator.first(haystack: db-titles)}" substring="*" replacement="</span><span>"/></span>
</f:else>
</f:if>
As I commented in the source code, everything works as it should under '<f:then>', but under '<f:else>', where I only want to use the first value of the array, the replaced part ('*' to </span><span>) is strangely rendered as text instead of HTML: <span>TextA</span><span>TextB</span>
How can this be?
Let me mention that I use the app "PHPStorm" for programming - is it possible that the program renders the source code wrong?
Thanks in advance for any help!
Without having found an explanation for the strange behaviour, I have found an solution: wrapping <v:format.replace ... /> with <f:format.raw> ... </> prevents that the tags converted to strings.
<f:if condition="{db-titles -> f:count()} > 1">
<f:then>
<v:iterator.for from="0" to="{db-titles -> f:count()}" iteration="i">
<span><f:format.raw><v:format.replace content="{db-titles.{i.index}}" substring="*" replacement="</span><span>"/></f:format.raw></span>
</v:iterator.for>
</f:then>
<f:else>
<span><f:format.raw><v:format.replace content="{v:iterator.first(haystack: db-titles)}" substring="*" replacement="</span><span>"/></(f:format.raw></span>
</f:else>
</f:if>
Using Typo3 8.7.19, and I was asked to include a set of links to documents/videos inside a page, so I thought about a description list. Each title would be the title of the link(s), and the description the actual links that should be rendered as
http://something.linky
So all the thing should become something like
<dl>
<dt>A title for this link</dt>
<dd>http://something.linky</dd>
</dl>
Looking at the documentation, on this component one should put each description like
Term 1|Description 1
Term 2|Description 2
Term 3|Description 3
But I'm not sure if is there any way to include links using this schema, or if I have to resort to using the default text component.
It can be possible, when you edit the fluid-Template.
First outsource the default fluid-templates.
Then edit this template:
Partials/Bullets/Type-2.html
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" xmlns:ce="http://typo3.org/ns/TYPO3/CMS/FluidStyledContent/ViewHelpers" data- namespace-typo3-fluid="true">
<f:if condition="{bullets}">
<dl class="ce-bullets">
<f:for each="{bullets}" as="definitionListItem">
<f:for each="{definitionListItem}" as="termDescription" iteration="termDescriptionIterator">
<f:if condition="{termDescriptionIterator.isFirst}">
<f:then>
<dt>{termDescription}</dt>
</f:then>
<f:else>
<dd>{termDescription}</dd>
</f:else>
</f:if>
</f:for>
</f:for>
</dl>
</f:if>
</html>
Just add a
<f:format.html>{termDescription}</f:format.html>
around
{termDescription}
Then you can write this in the description list.
Term1 | <LINK 1>Your description</LINK>
Term2 | http://something.linky
I want to select a logo depending on a check box of a page property I have added via extension. The variable selectcompany is shown correctly when dumping the variables.
I am running Typo3 8 LTS.
obj.logo {
<f:if condition="{field:selectcompany}==1">
<f:then>
file = fileadmin/template/private/images/Logo1.png
</f:then>
<f:else>
file = fileadmin/template/private/images/Logo0.png
</f:else>
</f:if>
}
Although the variable is set correctly, always Logo0.png is displayed. When the variable is set to 1, I expected Logo1.png.
If this is a TypoScript snippet, you can not fill in a Fluid condition there, but have to make use of the TypoScript variant of an if condition.
https://docs.typo3.org/m/typo3/reference-typoscript/master/en-us/Functions/If.html
On TypoScript, it is possible to use a condition (TYPO3 9.5.x syntax):
[page["selectcompany"] == 1]
obj.logo.file= fileadmin/Images/logo1.png
[GLOBAL]
Else, you could solve with fluid templating; it should be just:
<f:if condition="{data.selectcompany}">
<f:then>
<f:image src="fileadmin/template/private/images/Logo1.png" alt="" />
</f:then>
<f:else>
<f:image src="fileadmin/template/private/images/Logo0.png" alt="" />
</f:else>
</f:if>
I used <f:image> but I guess you could also go with a plain <img> tag, too.
Fluid Styled Content uses the f:render Viewhelper as such:
<f:render partial="Header" arguments="{_all}" />
I'd like to pass another info to the partial, like
<f:render partial="Header" arguments="{_all, settings : doThis}" />
But it seems to me that's the wrong way, as it throws an error.
I also tried accessing settings.doThis with f:alias, but no luck (or rather, skill) either.
How's that done correctly?
This is possible with the alias ViewHelper. I already used it with TYPO3 version 6 and 7.
Just extend the {_all} var as following
Partial
<f:alias map="{additionalVar: 'foobar'}">
<f:render partial="Partial" arguments="{_all}"/>
</f:alias>
Section
<f:alias map="{additionalVar: 'foobar'}">
<f:render section="Section" arguments="{_all}" />
</f:alias>
You can use the "additionalVar" variable as any other.
It is working with section and partial.
You can't, so just modify your settings (or any other var) in the controller yet or use ViewHelper, which allows you to declare vars in the view, like i.e.: v:variable.set of VHS ext.
It is possible to use this one, but don´t use the var 'settings'. This one is used by typoscript.
<f:render partial="Header" arguments="{_all, myvar:'myvalue'}" />
Try the <f:debug> tag in the Header Partial and see
You can use vhs viewhelper with fluid like below.
<v:variable.set value="{yourValue}" name="variable">
<f:render partial="Header" arguments="{_all, newVar:variable}" />
I am using the extension fluidpages and want to switch the layout by the typeNum.
is it possible to change the f:layout by by an condition?
This wont work:
<f:layout name="{f:if(condition: '{typeNum} == 666', then: 'PageAjax', else: 'Page')}"/>
Suggested approach:
<f:layout name="Page/{typeNum}"/>
Required files:
Resources/Private/Layouts/Page/0.html
Resources/Private/Layouts/Page/666.html
Please note: this only works if the {typeNum} variable is guaranteed to exist - if it does not, you will face a "template file not found" error with an empty filename. To avoid this, you can use the VHS extension's v:var.convert ViewHelper to ensure a proper value:
<f:layout name="Page/{typeNum -> v:var.convert(type: 'integer')}"/>
I got the same problem recently, and found the solution after a few researchings.
The problem is, you can not use nested fluid like <f:if>, <f:cObject> or others in <f:layout>. Otherwise, you will get a fatal error in the cache file, saying call to a member function getViewHelper() on a non-object. And when you look at the cache file, you will find it's because $self is not defined.
Therefore, my solution is, searching public function getLayoutName( in \TYPO3\CMS\Fluid\Core\Compiler\TemplateCompiler, and adding \$self = \$this; before \$currentVariableContainer = \$renderingContext->getTemplateVariableContainer();, just like generateCodeForSection()
I have now added the Condition in the Layout template. I get the typeNum from typoscript.
<f:if condition="{f:cObject(typoscriptObjectPath:'plugin.nc_template.settings.pageLayout')} == 'Default'">
<p>Default Template</p>
</f:if>
<f:if condition="{f:cObject(typoscriptObjectPath:'plugin.nc_template.settings.pageLayout')} == 'Ajax'">
<p>Ajax Template</p>
</f:if>
I found an example on the fedext Page, but could not get this to run:
https://fedext.net/blog/archive.html?tx_news_pi1[news]=55&tx_news_pi1[%40widget_0][currentPage]=8&cHash=f9c3165598a28d2aa98fd30ef115bb75
Can´t you use an if-statement instead?
IMHO this is easier to read - and if you need to add more arguments which depends on typeNum, it would stay readable.
<f:if condition="{typeNum} == 666">
<f:then>
<f:layout name="PageAjax">
</f:then>
<f:else>
<f:layout name="Page">
</f:else>
</f:if>