Fluid, access locallang.xlf from another extension - typo3

I have a own template and in this template I overwrite the templates of the tx_news:
plugin.tx_news.view {
templateRootPaths.1 = EXT:my_template/Resources/Private/News/Templates/
partialRootPaths.1 = EXT:my_template/Resources/Private/News/Partials/
layoutRootPaths.1 = EXT:my_template/Resources/Private/News/Layouts/
}
Now I would like to access the locallang.xlf from my_template. I tried this in the ext_table.php of my_template:
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addLLrefForTCAdescr(
'tt_content.pi_flexform.news_pi1.list', 'EXT:my_template/Resources/Private/Language/locallang.xlf');
And in this locallang.xlf I have:
<trans-unit id="tx_mytemplate.news">
<source>NEWSTEST</source>
</trans-unit>
And then in the tx_news List.html I have:
<f:translate key="tx_mytemplate.news" />
But I do not get any output.

There are two ways of accomplishing the task you are trying to do.
add the argument extensionName to the f:translate ViewHelper like so: <f:translate key="tx_mytemplate.news" extensionName="MyTemplate" />
add your locallang key as a full path like so <f:translate key="LLL:EXT:my_template/Resources/Private/Language/locallang.xlf:tx_mytemplate.news" />
I would prefer the first way, because it is shorter and you can let extbase/fluid decide where to search for the file.

Related

TYPO3 Fluid: Only SOME HTML tags are not rendered in fluid template

I've a very strange behavior and a question for TYPO3 experts: Some HTML tags are not rendered, the output is like: <form enctype="multipart/form-data" />
But only with the tags <form>, <input>, <label>, <figure>
All the other tags <div>, <p>, <span>, <button>, <h2>, even <script> are working perfectly.
Btw. it has nothing to do with <f:format.html> or <f:format.raw> because I don’t have an output from the system, it’s directly in the template.
Here is my template:
<html xmlns:f="https://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<f:layout name="Default" />
<f:section name="content">
<f:flashMessages />
<figure class="test">NOT working - tags rendered as text</figure>
<form action="">NOT working - tags rendered as text</form>
<div class="employees">working</div>
<p class="paragraph">working</p>
</f:section>
Another interesting thing is: The problem also occurs with the official “form” extension from TYPO3 8.7! Exactly the same problem, the mentioned tags are not rendered as HTML!
I hope somebody can help me with this problem. I’m getting crazy with this.
Environment
TYPO3: 8.7.22
PHP: 7.2
Extensions: realURL, DCE, Extensions Builder,
Grid Elements, VHS Fluid ViewHelpers, Yoast SEO, news
--- update: added TypoScript and layout file ---
TypoScript my extension (generated by the Extension Builder)
plugin.tx_rmdataschulungen_rmdataschulungen {
view {
templateRootPaths.0 = EXT:rmdata_schulungen/Resources/Private/Templates/
templateRootPaths.1 = {$plugin.tx_rmdataschulungen_rmdataschulungen.view.templateRootPath}
partialRootPaths.0 = EXT:rmdata_schulungen/Resources/Private/Partials/
partialRootPaths.1 = {$plugin.tx_rmdataschulungen_rmdataschulungen.view.partialRootPath}
layoutRootPaths.0 = EXT:rmdata_schulungen/Resources/Private/Layouts/
layoutRootPaths.1 = {$plugin.tx_rmdataschulungen_rmdataschulungen.view.layoutRootPath}
}
persistence {
storagePid = 106{$plugin.tx_rmdataschulungen_rmdataschulungen.persistence.storagePid}
#recursive = 1
}
features {
#skipDefaultArguments = 1
ignoreAllEnableFieldsInBe = 0
requireCHashArgumentForActionArguments = 1
}
mvc {
#callDefaultActionIfActionCantBeResolved = 1
}
}
Layout file (generated by the Extension Builder)
<html xmlns:f="https://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<div class="tx-rmdata-schulungen">
<f:render section="content" />
</div>
</html>
TypoScript (output page content)
page = PAGE
page.10 = FLUIDTEMPLATE
page.10 {
templateName = Default
templateRootPaths.1 = fileadmin/Resources/Private/Templates/Page
variables {
content < styles.content.get
nav < Navigation
searchbox < lib.searchField
}
}
You shouldn't use the concept of variables for such dynamic content because of not only this issue.
Check out this question and my answer for a detailed feedback
I solved my problem: The problem was indeed <f:format.html> BUT in the main template.
I always edited my extension template -> but with <f:format.raw> in my website template (for the general output) everything works fine (although I don’t understand why this special behavior regarding the HTML tags occurs).

TYPO3: How do I set the correct id in locallang for a flux:field inside a flux:object?

I'm creating a Flexible Content Element.
In my template configuration flux form I have a field, in an object, in a section. In my locallang.xlf, I can label my object and section, but I haven't been able to label my field successfully.
My template configuration looks like:
<f:section name="Configuration">
<flux:form id="element">
<flux:form.section name="settings.mysection">
<flux:form.object name="myobject">
<flux:field.input name="myfield" />
</flux:form.object>
</flux:form.section>
</flux:form>
</f:section>
The relevant part of my locallang.xlf looks like:
<trans-unit id="flux.element.sections.settings.mysection">
<source>This works</source>
</trans-unit>
<trans-unit id="flux.element.objects.myobject">
<source>This also works</source>
</trans-unit>
<trans-unit id="flux.element.fields.myfield">
<source>This doesn't work</source>
</trans-unit>
What should the id attribute be to label 'myfield'?
In your AdditionalConfiguration.php, add the following:
$TYPO3_CONF_VARS['BE']['lang']['debug'] = true;
Now you will see the full language label paths in the backend:
flux.element.objects.myobject.myfield
It seems this was changed for TYPO3 8.7 https://forge.typo3.org/issues/71095 to
$TYPO3_CONF_VARS['BE']['languageDebug'] = true;

Get layout name in front end - fluid typo3

I have a fluid typo3 site with single page layout.One menu have different layout.How to get the selected layout name in my main template?
main.html
<v:page.menu levels="1" as="sections">
<f:for each="{sections}" as="section" iteration="itemIteration">
<f:debug>{sections}</f:debug>
</f:for>
</v:page.menu>
sub.html
<f:layout name="Pagewithnav" />
<f:section name="Configuration">
<flux:form id="subnav" icon="{f:uri.resource(path: 'Icons/Page/logo.png')}" label="Sub Navigation">
<!-- Insert fields, sheets, grid, form section objects etc. here, in this flux:form tag -->
</flux:form>
<flux:grid>
<!-- Edit this grid to change the "backend layout" structure -->
<flux:grid.row>
<flux:grid.column colPos="0" colspan="4" name="main" label="Navigation wrapper" />
</flux:grid.row>
<flux:grid.row>
<flux:grid.column colPos="1" colspan="4" name="main" label="Main wrapper" />
</flux:grid.row>
</flux:grid>
</f:section>
<f:section name="Main">
<div class="sub_nav">
<div class="container">
<v:content.render column="0"/>
</div>
</div>
<div class="container">
<v:content.render column="1"/>
</div>
</f:section>
It depends on what exactly you mean by "Layout name":
If you mean fields of the pages table for each individual page then those will be available in each record when you iterate it in v:page.menu (for example, tx_fed_page_controller_action).
If you mean fields of pages but also when this variable is inherited (for example, backend_layout is and tx_fed_page_controller_action is as well, but each through different methods) it becomes more complex: you would need to walk through the root line and use the first non-empty value. For that, v:page.rootLine plus v:iterator.filter plus v:iterator.first can be of great help (put output from root line into filter to remove non-empty values then use the first VH to select the first value from that filtered result).
If you define this "layout" in a Flux form field on your page template it becomes a FlexForm variable which you can read with flux:form.data (with inheritance if not disabled and if templates match up through root line).
Depending on exactly which you mean there are quite a few possible solutions. If you are also looking for a recommendation about which one it makes sense to use: most likely you mean the layout you select in page properties (regardless of field) and for this, v:page.rootLine plus v:iterator.filter plus v:iterator.first is a nice and generic method to "slide select" any non-empty value from the root line of the current page.
You can get it with a variable in fluid
lib.templateName = TEXT
lib.templateName.stdWrap.cObject = CASE
lib.templateName.stdWrap {
cObject = TEXT
cObject {
data = levelfield:-2,backend_layout_next_level,slide
override.field = backend_layout
split {
token = pagets__
1.current = 1
1.wrap = |
}
}
ifEmpty = Default
}
page = PAGE
page.10 = FLUIDTEMPLATE
page.10 {
#...
variables.templateName < lib.templateName
}

Call ViewHelper from outside Fluid template

In my general page setup, I define the template as follows: page.10.template.file = fileadmin/template.html
Is there a way to call a MVC ViewHelper in this template? The snippet
{namespace xyz=PATH\TO\MY\ViewHelpers}
<xyz:myhelper argument="abc" />
does not work in the above template, it is surfaced as is.
It is not 100% clear for me, which cObject you use for your page template. If you would like to use Fluid ViewHelpers in your page template, then I would recommend to use FLUIDTEMPLATE for your page template.
1. FLUIDTEMPLATE
If you use FLUIDTEMPLATE for your page template, then you can use any available ViewHelper (from FLUID or any other ExtBase/Fluid extension) directly in your template (see example below).
TypoScript
page = PAGE
page.10 = FLUIDTEMPLATE
page.10 {
template = FILE
template.file = fileadmin/templates/template.html
partialRootPath = fileadmin/templates/Partials/
layoutRootPath = fileadmin/templates/Layouts/
variables {
content < styles.content.get
content.select.where = colPos=1
}
}
Content of file: fileadmin/templates/template.html
{namespace xyz=NAMESPACE\EXTENSION\ViewHelpers}
<f:layout name="Main" />
<f:section name="Content">
<xyz:myhelper argument="abc" />
<f:format.html parseFuncTSPath="">{content}</f:format.html>
</f:section>
Content of file: fileadmin/templates/Layouts/Main.html
<f:render section="Content" />
2. TEMPLATE
If you use TEMPLATE (with markers and subparts), then you can't directly use Fluid ViewHelpers in that template. But you could define a marker which renders the FLUID ViewHelper like shown below.
TypoScript
page = PAGE
page.10 = TEMPLATE
page.10 {
template = FILE
template.file = fileadmin/templates/template.html
marks {
CONTENT < styles.content.get
VIEWHELPER = FLUIDTEMPLATE
VIEWHELPER {
template = FILE
template.file = fileadmin/templates/viewhelper.html
partialRootPath = fileadmin/templates/Partials/
layoutRootPath = fileadmin/templates/Layouts/
}
}
workOnSubpart = DOCUMENT
}
Content of file: fileadmin/templates/template.html
<!--###DOCUMENT### Start-->
###VIEWHELPER###
###CONTENT###
<!--###DOCUMENT### end-->
Content of file: fileadmin/templates/viewhelper.html
{namespace xyz=NAMESPACE\EXTENSION\ViewHelpers}
<f:layout name="Main" />
<f:section name="Content">
<xyz:myhelper argument="abc" />
</f:section>
Content of file: fileadmin/templates/Layouts/Main.html
<f:render section="Content" />

Typo3: How can I pass dynamic data from typoscript to partial?

I try to pass dynamic data from TypoScript to a Partial.
Is it possible and how can I do that?
TS:
lib.mydata = TEXT
lib.mydata.value = 470
HTML Template:
<f:render partial="mypartial" arguments="{dataitem: lib.mydata}" />
HTML Partial:
<section id="mypartial">
<div class="xy">
mehr ...
</div>
</section>
Please use TypoScript typolink for generating Links!
<f:cObject typoscriptObjectPath="lib.mydata" />
With TypoScript
lib.mydata = TEXT
lib.mydata.value = mehr ...
lib.mydata.typolink.additionalParams = &data=470
Or use the typolink viewhelper
<f.link.page pageUid="1" additionalParams="{data:470}">mehr ...</f:link.page>
(untested)