Render TYPO3 Fluid partial from another extension - typo3

I want to render a section in a partial from another extension.
My setup is TYPO3 7.6.14 with fluid powered TYPO3 extensions including VHS.
As far as i know it is not possible with the fluid ViewHelper f:render. Here you only have the arguments "partial" and "section".
I found one solution using the VHS ViewHelper v:render.template.
The solution is explained here: https://www.wapplersystems.de/blog/typo3-fluid-render-partial-from-another-extension/
But with this ViewHelper I can only set the path to the partial, but not to the section.

Fluid supports a lookup chain for partials, templates and layouts. You can specify multiple directories in your extension and fluid will look in all of them (beginning at the highest index) until it finds a matching partial file.
plugin.tx_myextension.view {
partialRootPaths {
10 = EXT:my_extension/Resources/Private/Partials
20 = EXT:another_extension/Resources/Private/Partials
}
}
With this configuration fluid will look for every partial in your extension at another_extension/Resources/Private/Partials first and render it from there if it is present.

Related

Condition for backend layout name in Typo3 10+

I'm looking for a way to render a partial for when an element is placed it on a part of the backend layout and another partial for when the same element is placed it on another part of the backend layout.
My backend layout names are "Header" on top and "Normal" on the bottom. I want to render text-media element with one partial for when is on Header and another partial for when is on Normal.
For what I could find online seems that this must be done with typoscript. Particualrly I want to use typoscript condition because is the one that make more sense on my head.
I'm aware of this but the answers are not helping me at all.
This is the one that looks like something I could use.
[page["backend_layout"] == 'pagets__2']
page.bodyTagCObject.value.wrap = <body id="uid|" class="fullpage">
[end]
Any help is welcome even tutorials because clearly I have much to learn about typoscripting
You can pass the needed value as a variable to your FLUIDTEMPLATE-object.
The current backend-layout is available as pagelayout (Already with the 'backend_layout_next_level' taken into account).
page.10 = FLUIDTEMPLATE
page.10 {
variables {
pagelayout = TEXT
pagelayout.data = pagelayout
}
}
Solved it.
I have been able to solve this problem without useing Typoscript. (so I will keep ignoring typoscript :D )
Dropping the variables of the loaded templates (not partials) made me realized that there was a property holding the colPos of the backend layout so all I had to do was an if condition on the textmedia default template.
<f:if condition="{data.colPos} == 1">
If the colPos of the backend layout is 1 print something
</f:if>

How to use template partials in MASK Extension

I need to render a partial from my Main Template (SitePackage) within a MASK content element. The partial is located in the folder Resources/Private/Partials and the fluid code of my content element is located in Resources/Private/Extensions/Mask/Frontend/Templates.
This is my (testing) partial (Test.html):
<div class="header">
<h3>Dies ist ein Partial</h3>
</div>
In the MASK content element I try to render it with <f:render partial="Test"/>, but it doesen't work, the page is showing the following error message:
The Fluid template files "[...]/Resources/Private/Extensions/Mask/Frontend/Partials/Test.html", "[...]/Resources/Private/Extensions/Mask/Frontend/Partials/Test" could not be loaded.).
Is there a way to render a partial from outside my Extension folder?
Thanks in advance for any help!
Like for any FLUID templating you can add further paths to select layout, template or partial.
Just add the further paths with new numbers to the list of these paths.
In mask you define the paths like:
module.tx_mask.view {
layoutRootPaths.30 = EXT:your_site_extension/Resources/Private/Layouts
partialRootPaths.30 = EXT:your_site_extension/Resources/Private/Partials
templateRootPaths.30 = EXT:your_site_extension/Resources/Private/Templates
}
plugin.tx_mask.view {
layoutRootPaths.30 = EXT:your_site_extension/Resources/Private/Layouts
partialRootPaths.30 = EXT:your_site_extension/Resources/Private/Partials
templateRootPaths.30 = EXT:your_site_extension/Resources/Private/Templates
}
Mind the plural -s in "layoutRootPaths", "templateRootPaths" & "partialRootPaths"! > TYPO3 Docs - FLUIDTEMPLATE
But be careful if you mix different templating sets like page-templates, mask-/CE-templates, news-templates, ....
you might get naming conflicts!!

No default link classes in typo3 8 anymore?

In V7 all internal/external/download links got an additional class by default, like 'internal-link' or 'download'.
Looks like in V8 with the new CKEditor this feature is gone.
Is there a way to reimplement it via typoScript or some kind of yaml RTE config?
An automatic solution, not the solution where the user have to pick a custom style, thats our current workaround.
If these classes should be applied automatically to specific link types without enabling the editors to change those classes, you should go for TypoScript parseFunc:
https://docs.typo3.org/typo3cms/TyposcriptReference/Functions/Parsefunc.html?highlight=parsefunc
Especially makeLinks, tags and typolink should be useful here:
https://docs.typo3.org/typo3cms/TyposcriptReference/Functions/Makelinks.html#makelinks
https://docs.typo3.org/typo3cms/TyposcriptReference/Functions/Tags.html#tags
https://docs.typo3.org/typo3cms/TyposcriptReference/Functions/Typolink.html#atagparams
For example you would assign a specific class to an external http link automatically created by makelink like this:
parseFunc {
makelinks = 1
makelinks {
http {
keep = path
extTarget = _blank
ATagParams = class="external-link"
}
}
}

TYPO3 8, Form extension - best practice for custom yaml files

When generating forms with the form module the corresponding yaml files get stored in fileadmin/user_upload.
Now I want to integrate those yaml files into my sitepackage and thus into my CVS. Where is the correct place for them? In the example extension they are stored in Resources/... while I would think they have to go into Configuration/Yaml
And how do I configure the form extension to search them in that place?
While it's basically a matter of taste where exactly one saves his form definitions, I try to separate form configuration and form definitions.
From the official documentation:
[...] the form configuration allows you to define:
which form elements, finishers, and validators are available,
how those objects are pre-configured,
how those objects will be displayed within the frontend and backend.
In contrast, the form definition describes the specific form,
including
all form elements and their corresponding validators,
the order of the form elements within the form, and
the finishers which are fired as soon as the form has been submitted.
Furthermore, it defines the concrete values of each property of the mentioned aspects.
So, for more clarity I save all form configuration in a sitepackage under Configuration/Yaml/ and the form definitions under Resources/Private/Forms, neighbouring the templates.
I wrote a full tutorial how to use custom templates with EXT:form, which also includes the answers to your question.
In short:
Register YAML configuration with TypoScript in your extension root folder as ext_typoscript_setup.txt (as recommended1)
plugin.tx_form.settings.yamlConfigurations {
100 = EXT:my_extension/Configuration/Yaml/CustomFormSetup.yaml
}
module.tx_form.settings.yamlConfigurations {
100 = EXT:my_extension/Configuration/Yaml/CustomFormSetup.yaml
}
CustomFormSetup.yaml – setting up a new storage path
TYPO3:
CMS:
Form:
persistenceManager:
allowedExtensionPaths:
10: EXT:my_extension/Resources/Private/Forms/
allowSaveToExtensionPaths: true
allowDeleteFromExtensionPaths: true
1TypoScript inside an ext_typoscript_setup.txt is automatically loaded in both frontend and backend of your TYPO3 installation directly after installing your extension. This differs from other TypoScript files, which have to be included manually, e.g. as static templates. See official Form Framework documentation.
I'd suggest Resources/Private/Forms for your form definitions. The form extension clarifies how to register additional form definition paths.

#1237900529: The argument "each" was registered with type "array", but is of type "string" in view helper "TYPO3\CMS\Fluid\ViewHelpers\ForViewHelper"

I get the following error message #1237900529: The argument "each" was registered with type "array", but is of type "string" in view helper "TYPO3\CMS\Fluid\ViewHelpers\ForViewHelper" while trying to iterate through the rows of my data using the following FLUIDTEMPLATE (FT) iteration:
<h2>Sources</h2>
<f:for each="{content_source}" as="source">
<p>{source.header}</p>
</f:for>
<h2>Contact</h2>
<f:for each="{content_contact}" as="contact">
<p>{contact.header}</p>
</f:for>
I'm running Typo3 6.2.14 and would like to parse this HTML to match with BootStrap's architecture in my custom built template. I don't have much knowledge on Typoscript & FT; it is however preferable for me to use FT over TypoScript to make conditions for html parsing. What should I adjust if I have the following TypoScript:
10 = FLUIDTEMPLATE
10{
file= fileadmin/Templates/index.html
layoutRootPath = fileadmin/Templates/layouts/
partialRootPath = fileadmin/Templates/partials/
variables {
content_source < styles.content.get
content_source.select.where = colPos=3
content_contact < styles.content.get
content_contact.select.where = colPos=4
}
}
For posterity, since this question is old and likely resolved already:
When you consume a variable from TypoScript this way, you get strings of rendered content - not an array of content records or an array of rendered content HTML strings. So the error is correct.
There are two main roads one would normally take to style the HTML output of the content you render, depending on the type of content element:
Change the TS wrapping etc. (if you use css_styled_content) or override the templates you want to change (if you use fluid_styled_content).
Override the templates you want to change, for all content types and plugins which use either FLUIDTEMPLATE TS object or Extbase MVC.
Lastly, there are third party ViewHelpers you can use in Fluid to fetch raw content records and render them as well - which will allow you to apply things like wrapping to content elements as part of the Fluid template. See https://fluidtypo3.org/viewhelpers/vhs/master/Content/GetViewHelper.html and v:content.render counterpart.