Add Field for custom class in TYPO3 CE - typo3

I'm trying to add a field for adding a custom class to all TYPO3 CE (i.e Bootstrap Classes).
The Field is shown in the BE CEs and I'm able to write f.e. col-md-6 in this field.
The DB has a field called bootstrap_css where the values are stored.
But I've no Idea on how to get a wrap around the CE in FE with that custom class:
Example: Adding col-md-6 in the BE Field should result in something like this:
<div class="col-md-6">
<div class="csc-default">
....
</div>
</div>
Any Idea?

A free input for classes is generally considered bad practice (-> separation of concerns).
For such cases, I use the classic 'header_layout' method, based on www.typo3wizard.com/en/snippets/cool-stuff-typoscript/using-the-layout-field-in-tt-content-and-pages.html
This works very robustly, and editors can pick any value you offer them.
It IS a workaround, but it's been used for ages.
The header_layout box has been used because it's in a convenient place for editors. Originally, it was designed to pick a layout just for the element.
in page TSConfig:
TCEFORM.tt_content {
// Layout-Selector
header_layout.altLabels.0 = Normal
header_layout.altLabels.1 = Kasten
header_layout.altLabels.2 = Bilder 1/2
header_layout.altLabels.3 = Bilder 1/3
header_layout.altLabels.4 = Dokumente 1/2 (mit Rand)
header_layout.altLabels.5 = Dokumente 1/3 (mit Rand)
// everything higher than 5 goes here
header_layout.addItems {
// 6 = Box für wichtige Daten
// 7 = Box für Kosten
// 8 = Box für Arbeiten / Literatur
}
// Remove items if less than 5
// 100 is "hidden"
header_layout.removeItems = 100
}
Then in page TS:
Assuming we want to wrap text and textpic elements:
tt_content.text.stdWrap.outerWrap.cObject=CASE
tt_content.text.stdWrap.outerWrap.cObject=CASE
tt_content.text.stdWrap.outerWrap.cObject{
key.field = header_layout
default=TEXT
default.value=|
1=TEXT
1.value=<aside class="kasten halfimg clearfix">|</aside>
2=TEXT
2.value=<div class="halfimg clearfix">|</div>
3=TEXT
3.value=<div class="thirdimg clearfix">|</div>
4=TEXT
4.value=<div class="halfimg-border clearfix">|</div>
5=TEXT
5.value=<div class="thirdimg-border clearfix">|</div>
}
tt_content.textpic.stdWrap.outerWrap.cObject=CASE
tt_content.textpic.stdWrap.outerWrap.cObject{
key.field = header_layout
default=TEXT
default.value=|
1=TEXT
1.value=<aside class="kasten halfimg clearfix">|</aside>
2=TEXT
2.value=<div class="halfimg clearfix">|</div>
3=TEXT
3.value=<div class="thirdimg clearfix">|</div>
4=TEXT
4.value=<div class="halfimg-border clearfix">|</div>
5=TEXT
5.value=<div class="thirdimg-border clearfix">|</div>
}
So basically, you tap into the rendering of css_styled_content and tell it to wrap that content element depending on what is set in header_layout.

Related

typo3 append frame_class to layouts

I want to adjust my rendering of layout and frame elements in the frontend.
I have different layouts defined via typoscript. Now I want to define two frames, that should adjust the wrapped elements on layout level.
Currently the two layers (layout and frame) gets rendered like the following:
(exact classes might differ)
<div class="layout-class">
<div class="frame-class">
<p>This is Content</p>
</div>
</div>
I want to change that behaviour via Typoscript to render it like the following:
<div class="layout-class frame-class">
<p>This is Content</p>
</div>
Is there a possibility to do so?
I tried the following:
tt_content.stdWrap.innerWrap.cObject = TEXT
tt_content.stdWrap.innerWrap.cObject {
field = frame_class
required = 1
noTrimWrap = |field:frame_class-| |
}
Solution 1:
tt_content.stdWrap.innerWrap.cObject = COA
tt_content.stdWrap.innerWrap.cObject {
10 = TEXT
10.field = layout_class
20 = TEXT
20.field = frame_class
20.wrap = -|
}
Solution 2:
tt_content.stdWrap.innerWrap.cObject = TEXT
tt_content.stdWrap.innerWrap.cObject {
value = {field:layout_class}-{field:frame_class}
stdWrap.insertData = 1
}
Deactivate css_styled_content
Activate fluid_styled_content
Adjust your project's stylesheet to fluid_styled_content classes

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: pass variable to typoscript via cObject?

I would like to create a dropdown login form in my menu, like in this example: http://bootsnipp.com/snippets/featured/fancy-navbar-login-sign-in-form
I have this cObject that calls typoscript for the navigation:
<f:cObject typoscriptObjectPath="menu.navbar" />
I need to get the content of the login form somehow into the menu typoscript. Is it maybe possible to pass a variable (in my case the login form) to typoscript via cObject ?
f:cObject has a data Attribute, that can take different kind of values.
Usually the data attribute takes an array and you then can use those values to render content objects using the .field properties in typoscript.
An example:
lib.testFluid = COA
lib.testFluid {
wrap = <div>|</div>
10 = TEXT
10.field = title
10.wrap = <b>|</b>
20 = TEXT
20.field = content
}
If you have TypoScript like that, a data array, that has the keys title and content is expected. Rendering such a content object would possibly look like this in fluid:
<f:cObject typoscriptObjectPath="lib.testFluid" data="{title: 'Hello World', content: 'Foobar'}" />
However, if you just have some "content" (e.g. string content) and want to output it at one place in your content object, you can pass it in as-is and use the .current property in TypoScript to let it use the "current value".
lib.testFluid = COA
lib.testFluid {
wrap = <div>|</div>
10 = TEXT
10.current = 1
10.wrap = <b>|</b>
}
And in fluid:
<f:cObject typoscriptObjectPath="lib.testFluid" data="simple text content" />
or
<f:cObject typoscriptObjectPath="lib.testFluid">simple text content</f:cObject>
Of course data also takes normal variables. Depending on your use case, one of those cases might be what you want.
Edit: However, it seems to be a bit more complicated, if you want to use data together with an HMENU. The nested TMENU instances (or other menus) have different data values because it's being overwritten by HMENU with the current page for that menu entry. You probably have to do some convoluted wrapping, or avoid inserting the desired content in a TMENU/GMENU et cetera. I suggest to instead render the menu completely with fluid in that case.
Edit 2 - Example
Something like this is not going to work:
lib.testFluid = HMENU
lib.testFluid {
special = directory
special.value = 1
wrap = <ul>|</ul>
1 = TMENU
1 {
NO.stdWrap.cObject = COA
NO.stdWrap.cObject {
10 = TEXT
10.field = title
10.noTrimWrap = || |
20 = TEXT
20.current = 1
}
}
}
20.current = 1 won't include the value from data supplied by the fluid viewhelper, because the "data" of TMENU has been changed to the current page by the HMENU content object.
However, it should be possible to wrap a COA or similar around the HMENU to insert the desired content somewhere around the HMENU.

"Menu of subpages" doesn't work in a Typo3 Fluid template while fetching a record from a page

I'm trying to add a "user controlled" footer in the main layout of a Typo3 Fluid based template.
This means that I've added a backend layout with four columns in a special back-end page called "footer page". A user is able to add content elements in those columns using the WEB > PAGE module.
Whenever a user adds a content element (text, text w/images, bullet lists, etc...) in one of the columns, everything works and the content is correctly displayed.
But when the user tries to add a special menu content element, the menu isn't displayed and the column container stays empty.
the main layout
<body>
...
<div id="footer">
<f:cObject typoscriptObjectPath="lib.footer" />
</div>
</body>
main PAGE typoscript
page = PAGE
page {
# Regular pages always have typeNum = 0
typeNum = 0
10 = FLUIDTEMPLATE
10 {
#file = {$filepaths.templates}index_f.html
partialRootPath = {$filepaths.templates}partials/
layoutRootPath = {$filepaths.templates}layouts/
variables {
...
footer < lib.footer
...
}
}
}
lib.footer typoscript
lib.footer = COA
lib.footer {
10 = CONTENT
10 {
table = tt_content
select.pidInList = {$contentpage.footerPID}
select.where = colPos = 901
select.orderBy = sorting
stdWrap.wrap = <div id="footer-widget-1" class="col205">|</div>
}
20 = CONTENT
20 {
table = tt_content
select.pidInList = {$contentpage.footerPID}
select.where = colPos = 902
select.orderBy = sorting
stdWrap.wrap = <div id="footer-widget-2" class="col205">|</div>
}
...
}
Am I doing something wrong or is it a bug?
Typo3 version is 6.0.4
You may want to have a look at the VHS extension for TYPO3 - it contains one ViewHelper in particular which would let you render content elements from any column on any page (by UID). It can even render content elements from a list of content element UIDs (which you could specify in TypoScript, select in a FlexForm, make editable in the constants editor etc.):
http://fedext.net/viewhelpers/vhs/Content/RenderViewHelper.html
Many times the ViewHelpers from VHS will let you do exactly the same as TS lets you do, but do so directly in Fluid and with the option to manually control the HTML that is output.
Cheers,
Claus aka. NamelessCoder

Custom Element Preset => Form Field: Images

I tried to create a typo3 template with a special div-tag.
The editors should have the possibility to add images to the page-element. The goal should be the following code:
<div id="special_div_tag_in_template">
<img src="first_image_from_editor_in_page_element.png" />
<img src="second_image_from_editor_in_page_element.png" />
<img src="third_image_from_editor_in_page_element.png" />
</div>
Is there a possibility to create a custom element preset / form field?
I hope some one has a hint how to solve with this problem.
Thanks, Andreas
You can use the media field of the page properties:
lib.headerImage = COA
lib.headerImage {
wrap = <div id="special_div_tag_in_template">|</div>
10 = IMAGE
10 {
file {
import = uploads/media/
import {
field = media
listNum = 0
}
// set the dimensions if you want
height = 200
width = 100m
}
}
// create a copy and select 2nd image
20 < .10
20.file.import.listNum = 1
// create a copy and select 3rd image
30 < .10
30.file.import.listNum = 2
}
Take a look at the TYPO3 Wiki for more examples of header images.
A different approach would be to create DS/TO in TemplaVoila and insert this as a flexible content element (FCE)