Transfer data from Fluid to Typoscript plugin settings - typo3

I have a Fluid template with this line of code:
<f:cObject typoscriptObjectPath="lib.psStadtDetail" data="{stadt}" />
And this bit of Typoscript to call a plugin:
lib.psStadtDetail = USER_INT
lib.psStadtDetail {
userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
pluginName = Pferdeservice
extensionName = Pferdeservice
vendorName = Pferdeservice
Controller = User
action = search
switchableControllerActions.User.1 = list
features < plugin.tx_pferdeservice.features
view < plugin.tx_pferdeservice.view
persistence < plugin.tx_pferdeservice.persistence
settings {
StaticZip < temp.psStadtZip
#StaticZip = 70173
}
}
Now, the settings for this plugin, specifically StaticZip should come from the Fluid template. But the data is not being transferred by temp.psStadtZip
temp.psStadtZip = COA
temp.psStadtZip {
10 = TEXT
10.value.current = 1
20 = TEXT
20.value.dataWrap = {field:plz}
}
When I output temp.psStadtZip only, I get the correct zip code.
Why can't I use this for the plugin settings? How do I accomplish this?

The property settings can only be used for an array of keys.
10 = FLUIDTEMPLATE
10 {
file = fileadmin/templates/MyTemplate.html
settings {
name = Car
color = red
}
}
See TYPO3 TypoScript Reference (latest (8-dev)): Content Objects (cObject) > Fluidtemplate > settings
Instead you should use variables which is an array of cObjects.
lib.psStadtDetail {
# Replace settings with variables
variables {
StaticZip < temp.psStadtZip
#StaticZip = 70173
}
}
See TYPO3 TypoScript Reference (latest (8-dev)): Content Objects (cObject) > Fluidtemplate > variables

Related

Typo3 Custom filed on Content Element

Can I add a custom field to each content-element where I can add a string?
In typoscript I would be able to read this string and print it in class="" attribute is that possible?
There is the note field for each content element Can I red this in typoscript and paste it in the class attribute?
CONTENT < styles.content.get
CONTENT.renderObj.stdWrap.dataWrap=<div class="{NOTE??}">|</div>
Thanks
UPDATE:
Is something like this possible:
CONTENT < styles.content.get
CONTENT.renderObj.stdWrap {
key.field = layout
4 = TEXT
4.value = <div class="csc-default blue">|</div>
5 = TEXT
5.value = <div class="csc-default meineklasse2">|</div>
6 = TEXT
6.value = <div class="csc-default meineklasse3">|</div>
}
As to stay with a given CI it normally is no good option to enable editors to enter CSS-class names by hand. A better way would be to have a set of possible classes the editor can choose from.
This can be done if you use the already available field layout in the tt_contentrecord.
As the layoutfield is type int you might need a 'translation' to your expected class names, or you stay with numbered classes like frame-layout-1 to frame-layout-3. This is the (in FSC) build in solution and available option.
You can enhance this option and also modify it.
Enhancing the selection is done in page TSconfig:
// Adding more layouts:
TCEFORM.tt_content.layout.addItems {
4 = my special layout
5 = my other special layout
}
// Modifying layouts names:
TCEFORM.tt_content.layout.altLabels {
1 = my default layout
}
// remove items
TCEFORM.tt_content.layout.removeItems = 2,3
In FSC this field is evaluated in the layout template (Resources/Private/Layouts/Default.html) (if you also use a frame_class ????)
[...]
<div id="c{data.uid}" class="frame frame-{data.frame_class} frame-type-{data.CType} frame-layout-{data.layout}{f:if(condition: data.space_before_class, then: ' frame-space-before-{data.space_before_class}')}{f:if(condition: data.space_after_class, then: ' frame-space-after-{data.space_after_class}')}">
[...]
But you can override the Default.html file with your own, like in every fluid templating system. Just copy the original file to your own space and add the new location to the template (Layout) paths.
That could end in something like:
[...]
<div id="c{data.uid}" {f:render.section(name:'layout-selection', arguments={layout:'layout'})} ... >
[...]
<f:section name="layout-selection">
<f:switch expression="{layout}">
<f:case value="1">class="normal"</f:case>
<f:case value="4">class="special"</f:case>
<f:case value="5">class="very-special"</f:case>
<f:defaultCase>class="default"</f:defaultCase>
</f:switch>
</f:section>
based on the version of your TYPO3 the template paths of FSC can be configured like:
(up to TYPO3 7):
lib.fluidContent {
templateRootPaths {
20 = EXT:my_extension/Resources/Private/Templates/
}
partialRootPaths {
20 = EXT:my_extension/Resources/Private/Partials/
}
layoutRootPaths {
20 = EXT:my_extension/Resources/Private/Layouts/
}
}
or (since TYPO3 8): (Manual)
lib.contentElement {
templateRootPaths {
20 = EXT:my_extension/Resources/Private/Templates/
}
partialRootPaths {
20 = EXT:my_extension/Resources/Private/Partials/
}
layoutRootPaths {
20 = EXT:my_extension/Resources/Private/Layouts/
}
}
I found a solution which works for me.
tt_content.stdWrap.innerWrap.cObject = CASE
tt_content.stdWrap.innerWrap.cObject {
key.field = layout
4 = TEXT
4.value = <div class="blue"><div class="container-fluid"><div class="design">|</div></div></div>
5 = TEXT
5.value = <div class="white"><div class="container-fluid"><div class="design">|</div></div></div>
6 = TEXT
6.value = <div class="grey"><div class="container-fluid"><div class="design">|</div></div></div>
}

Typo3 Fluid Templates How to add multiple templates

I have a finished static HTML Template. I need to map it to typo3 so the content is dynamic. I followed following tutorial: https://docs.typo3.org/typo3cms/SitePackageTutorial/FluidTemplates/Index.html
This works perfectly, but now I wonder how I can change the template per site? I made template for each site i.e Gallerie.html, Contact.html and they are linked to the same Layout as Header and Footer is always the same.
How do I now tell the page About us to use the Gallerie.html?
My setup.typoscript:
page = PAGE
page {
typeNum = 0
// Part 1: Fluid template section
10 = FLUIDTEMPLATE
10 {
templateName = TEXT
templateName.stdWrap.cObject = CASE
templateName.stdWrap.cObject {
key.data = pagelayout
pagets__default = TEXT
pagets__default.value = Default
default = TEXT
default.value = Default
}
templateRootPaths {
0 = EXT:eventmanagement/Resources/Private/Templates/Page/
1 = {$page.fluidtemplate.templateRootPath}
}
partialRootPaths {
0 = EXT:eventmanagement/Resources/Private/Partials/Page/
1 = {$page.fluidtemplate.partialRootPath}
}
layoutRootPaths {
0 = EXT:eventmanagement/Resources/Private/Layouts/Page/
1 = {$page.fluidtemplate.layoutRootPath}
}
dataProcessing {
10 = TYPO3\CMS\Frontend\DataProcessing\MenuProcessor
10 {
levels = 1
includeSpacer = 1
as = mainnavigation
}
}
}
At the Moment it loads the Default.html Template from eventmanagement/Resources/Private/Templates/Page/ on every page. I created now a second Template called Gallerie.html in eventmanagement/Resources/Private/Templates/Page/ how do I add this now to the page Gallerie in the Backend?
I don't know if it's very useful to have for (nearly) every page another template but in general that's possible. Just consider that in the root-line always that template is used that is defined on the current level or - if not existing - that, that is found first while going up the root-line.
For every additional template you've to add a section inside this snippet from above:
templateName.stdWrap.cObject {
key.data = pagelayout
pagets__default = TEXT
pagets__default.value = Default
default = TEXT
default.value = Default
}
So including the option about us the snippet could look like this:
templateName.stdWrap.cObject {
key.data = pagelayout
pagets__default = TEXT
pagets__default.value = Default
default = TEXT
default.value = Default
pagets__aboutus = TEXT
pagets__aboutus.value = AboutUs
aboutus = TEXT
aboutus.value = AboutUs
}
Additional you still have to change the TCA probably to include the options in the drop-down-button.

How to integrate a html template to typo3

I'am new to typo3 and I want to integrate my HTML template in it. but I can't add my content to the pages threw the dashboard all I get is a blank page.
I'am using TYPO3 v8
Greetings!
The steps you need to do for template integration in TYPO3 8
TYPOSCRIPT
Tell TYPO3 by where the templates should be get.
page = PAGE
page.10 {
templateRootPaths {
10 = PATH TO YOUR TEMPLATES
}
layoutRootPaths {
10 = PATH TO YOUR LAYOUTS
}
partialRootPaths {
10 = PATH TO YOUR PARTIALS
}
templateName = TEXT
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 = Home
}
}
LAYOUTS
It's not required to create a layout, but i suggest to do it, also if you have just one type of template.
The layouts ( in TYPO3 called Backend Layouts ) can be created in TYPO3 backend and the backend layouts are saved in database. But you can save the backend layouts configuration in a file.
Hint: Try save the backend layouts configuration in files so you can add to
git
Example of backend layout configuration:
mod.web_layout.BackendLayouts {
Home # identified by this name {
title = Home # this is shown in backend when you select the layout
icon = EXT:example_extension/Resources/Public/Images/BackendLayouts/default.gif
config {
backend_layout {
colCount = 1
rowCount = 1
rows {
1 {
columns {
1 {
name = Content
colPos = 1 # this is important, i'm talking about colPos below
}
}
}
}
}
}
}
}
ColPos meaning: you can have multiple columns in a layout, and the colPos is used to render the content in frontend. This is what will be used later in template <f:cObject typoscriptObjectPath="lib.dynamicContent" data="{colPos: 1}" />
The above configuration should be included in PageTs. This is found if you edit a page and go to Resources tab.
Typoscript configuration of lib.dynamicContent
lib.dynamicContent = COA
lib.dynamicContent {
5 = LOAD_REGISTER
5 {
colPos.cObject = TEXT
colPos.cObject {
field = colPos
ifEmpty.cObject = TEXT
ifEmpty.cObject {
value.current = 1
ifEmpty = 0
}
}
pageUid.cObject = TEXT
pageUid.cObject {
field = pageUid
ifEmpty.data = TSFE:id
}
contentFromPid.cObject = TEXT
contentFromPid.cObject {
data = DB:pages:{register:pageUid}:content_from_pid
data.insertData = 1
}
wrap.cObject = TEXT
wrap.cObject {
field = wrap
}
maxItems.cObject = TEXT
maxItems.cObject {
field = maxItems
ifEmpty =
}
}
20 = CONTENT
20 {
table = tt_content
select {
includeRecordsWithoutDefaultTranslation = 1
orderBy = sorting
where = {#colPos}={register:colPos}
where.insertData = 1
pidInList.data = register:pageUid
pidInList.override.data = register:contentFromPid
max.data = register:maxItems
// select.languageField setting is needed if you use this typoscript in TYPO3 < v7
// languageField = sys_language_uid
}
stdWrap {
dataWrap = {register:wrap}
required = 1
}
}
90 = RESTORE_REGISTER
}
lib.dynamicContentSlide < lib.dynamicContent
lib.dynamicContentSlide.20.slide = -1
lib.dynamicContentFirst < lib.dynamicContent
lib.dynamicContentFirst.20.select.max = 1
Home layout html integration
<f:render section="main" />
Home template integration
<f:layout name="Home" />
<f:section name="content">
// content
<f:cObject typoscriptObjectPath="lib.dynamicContent" data="{colPos: 1}" />
</f:section>
Now we have the setup of layouts and templates. Hope that you have a basic setup of TYPO3 ( a root page at least and a template setup )
If you don't have this setup already, follow the next steps:
Create a root page
Go with list on root page
Create a Template record - go in Options tab and check Clear -> Constants and Clear -> setup and check also Rootlevel
Go in Includes tab and select from the multiple selectbox fluid_styled_content
Paste the TYPOSCRIPT configuration in the created template ( check General Tab )
Edit Root page and go to the Appearance tab to select the Backend Layout.

TYPO3: Backend Layout Condition in TypoScript

I'd like to change the way elements are rendered depending on the page's backend layout.
Changing the fluid styled content template depending on the backend layout works as following:
[globalVar = TSFE:page|backend_layout = 1][globalVar = TSFE:page|backend_layout = 2]
lib.fluidContent.templateRootPaths.10 = EXT:ds_res/Resources/Private/Templates/ContentTemplates/
[global]
If it's 1 or 2, then use the other templates.
However, this only works if the BE layout is set directly at the page and not when it's inherited from its parent.
How to fix this?
Running TYPO3 7.6.15
In TYPO3 7.5 "Backend Layout"-Conditions has been simplified with "pagelayout" in Typoscript. Example:
page.10 = FLUIDTEMPLATE
page.10 {
file.stdWrap.cObject = CASE
file.stdWrap.cObject {
key.data = pagelayout
default = TEXT
default.value = EXT:sitepackage/Resources/Private/Templates/Home.html
3 = TEXT
3.value = EXT:sitepackage/Resources/Private/Templates/1-col.html
4 = TEXT
4.value = EXT:sitepackage/Resources/Private/Templates/2-col.html
}
}
Instead of:
field = backend_layout
field.data = levelfield:-2,backend_layout_next_level,slide
field.ifEmpty = default
Maybe this also works in your conditions like this:
[globalVar = TSFE:page|pagelayout = 1]
However, you should not change the used template file with [xy]-conditions and prefer using a CASE shown in the example above. Each number is the UID of a backend_layout by the way.
In TYPO3 9.5+ you can use typoscript conditions like:
[page["backend_layout"] == 'pagets__2']
page.bodyTagCObject.value.wrap = <body id="uid|" class="fullpage">
[end]
Edit:
As Bernd has mentioned use backend_layout only if you need the real defined field. If you need the computed value (e.g. for a sub page getting its layout from the backend_layout_next_level from a parent page) use pagelayout with a case like:
bodyTagCObject = TEXT
bodyTagCObject.value.field = uid
bodyTagCObject.value.wrap.cObject = CASE
bodyTagCObject.value.wrap.cObject{
key.data = pagelayout
default = TEXT
default.value = <body id="uid|" class="standard">
pagets__2 = TEXT
pagets__2.value = <body id="uid|" class="fullpage">
}
We use this solution
page = PAGE
page.10 = FLUIDTEMPLATE
page.10 {
templateName = TEXT
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 = Index
}
layoutRootPaths {
10 = EXT:yourext/Resources/Private/Layouts
}
partialRootPaths {
10 = EXT:yourext/Resources/Private/Partials
}
templateRootPaths {
10 = EXT:yourext/Resources/Private/Templates
}
}
This approach is when u do not have the Backendlayouts in the DB (made through the backend) but include them from files. As there is no uid then you go by the templatename.
Example:
If you use this PageTS:
mod.web_layout.BackendLayouts {
Blankpage {
title = Blankpage
name = Blankpage
icon = EXT:yourext/Resources/Public/Icons/BackendLayouts/Blankpage.jpg
config {
backend_layout {
colCount = 1
rowCount = 2
rows {
1 {
columns {
1 {
name = Nameofthecolumn
colPos = 0
colspan = 1
}
}
}
2 {
columns {
1 {
name = Nameofthesecondcolumn
colPos = 1
colspan = 1
}
}
}
}
}
}
}
You will need a Template.html with the name Blankpage.html within your EXT-Templates.
So you can add more Templates and Backendlayouts without touching the TS again. Simply add PageTS and a html-template.
There is a feature available which avoids having that code duplicated
page.10 = FLUIDTEMPLATE
page.10 {
templateName = TEXT
templateName.stdWrap.cObject = CASE
templateName.stdWrap.cObject {
key.data = pagelayout
....
As you can not handle the inherited layouts in conditions you need to use typoscript. My solution is this:
page.10 = FLUIDTEMPLATE
page.10 {
templateRootPaths.1 = {$resDir}/Private/Templates
partialRootPaths.1 = {$resDir}/Private/Partials
layoutRootPaths.1 = {$resDir}/Private/Layouts
templateName = TEXT
templateName.cObject = CASE
templateName.cObject {
key.data = levelfield:-1, backend_layout_next_level, slide
key.override.field = backend_layout
#Default Template
default = TEXT
default.value = subpage
# homepage
pagets__homepage = TEXT
pagets__homepage.value = homepage
pagets__subpage = TEXT
pagets__subpage.value = subpage
}
variables {
:
pageLayout = TEXT
pageLayout.data = levelfield:-1, backend_layout_next_level, slide
pageLayout.override.field = backend_layout
// since TYPO3 7 this already is computed by the core and this gives the same:
pageLayout = TEXT
pageLayout.data = pagelayout
:
}
}
Avoid using file for better implementation with ..RootPaths.
As we use backendlayouts defined in files (which gets included in the pageTSconfig) the key names starting with pagets__, you also might use the numbers of backend_layout records.
I use the constant {$resDir} to define the root of resources which can be changed in an easy way. In a siteextension this could be:
resDir = EXT:site_project1/Resources
I also define a fluid variable with the currently active page layout for further differentiation in the templates.
If you want the ...RootPaths to be different for each layout you need to build cObject with a CASE obejct similar to my selection of the template name.
In general: all this could be handled in the fluid templates if you have the backend layout available in your variables: you only need to have one starting template, which calls a layout where all further calls to partials are individualized by the current layout like
<f:render partial="{pageLayout}/header" arguments="{_all}" />
TYPO3 11.x:
[tree.pagelayout == 2]
...
[global]
https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/11.0/Feature-88276-TypoScriptConditionForPageLayout.html

Typo3 extbase include html2pdf

How to include html2pdf in extbase v6.1 extension ?
I am writing an extension, there I need to convert created field information to pdf with nice table structure.
Thank you.
I do not understand the problem?! In the documentation of html2pdf there are different examples. You could write a PDFController and trigger this controller with a typenum and special headercode.
pdf = PAGE
pdf {
typeNum = 300
10 = USER
10 {
userFunc = tx_extbase_core_bootstrap->run
pluginName = PLUGINNAME
extensionName = EXTENSIONNAME
controller = Pdf
action = html2pdf
switchableControllerActions {
Pdf {
1 = html2pdf
}
}
settings =< plugin.tx_yourext.settings
persistence =< plugin.tx_yourext.persistence
view =< plugin.tx_yourext.view
}
config {
disableAllHeaderCode = 1
additionalHeaders = Content-type:application/pdf
xhtml_cleaning = 0
admPanel = 0
}
}