The official TYPO3 Documentation explains how to create (or copy) and use a lib.dynamicContent to render columns into a Fluidtemplate.
I do not understand exactly whats going on in this example.
The TypoScript there is:
lib.dynamicContent = COA
lib.dynamicContent {
10 = LOAD_REGISTER
10.colPos.cObject = TEXT
10.colPos.cObject {
field = colPos
ifEmpty.cObject = TEXT
ifEmpty.cObject {
value.current = 1
ifEmpty = 0
}
}
20 = CONTENT
20 {
table = tt_content
select {
orderBy = sorting
where = colPos={register:colPos}
where.insertData = 1
}
}
90 = RESTORE_REGISTER
}
I use this snippet in a ton of TYPO3 projects and often had asked myself whats going on there.
I have changed this by experimenting a bit and ended with:
lib {
dynamicContent = COA
dynamicContent {
10 = CONTENT
10 {
table = tt_content
select {
orderBy = sorting
where {
data = field:colPos
wrap = colPos=|
}
}
}
}
}
That seems to do "exactly the same" thing - it outputs my content when called via cObject ViewHelper.
Can somebody explain if or why this is the worse way to render Content?
Here's the link to the lib.dynamicContent-doc: https://docs.typo3.org/c/typo3/cms-fluid-styled-content/master/en-us/Installation/InsertingContentPageTemplate/Index.html#based-on-the-fluidtemplate-content-object-cobj
Here you go!
you can try this,
# Clear out any constants in this reserved room!
styles.content >
# get content
styles.content.get = CONTENT
styles.content.get {
table = tt_content
select.orderBy = sorting
select.where = colPos=0
}
# Left Column
styles.content.getLeft < styles.content.get
styles.content.getLeft.select.where = colPos=1
# Right content
styles.content.getRight < styles.content.get
styles.content.getRight.select.where = colPos=2
Also, you can use variable in the fluid page object, check this out:
lib.pageTemplate = FLUIDTEMPLATE
lib.pageTemplate {
variables {
content = CONTENT
content {
table = tt_content
select.orderBy = sorting
select.where = colPos=0
}
contentRight = CONTENT
contentRight {
table = tt_content
slide = -1
select.orderBy = sorting
select.where = colPos=2
}
}
}
You can find out more here:
Adding the page content to a fluid template
Typo3 7.6 typoscript problems with markers
Hope this make sense, Cheer...!
You should look at this snippet together with some information about the Fluid view helper <f:cObject> which can be found here: https://docs.typo3.org/other/typo3/view-helper-reference/9.5/en-us/typo3/fluid/latest/CObject.html
As you can see there are the parameters data, currentValueKey and table that will be handed over to the typoscriptObjectPath, which is why the snippet makes perfect sense. The reason is, that it's a bit hard to put the different options into the where clause of the CONTENT object. So it increases readability and those registers can be easily extended.
So the register in this example is used to put in either the value of the data field colPos or if that is empty it will take the current value from the currentValueKey and if that is empty too it will fall back to a value of 0 to make sure the query won't produce an exception.
lib.dynamicContent = COA
lib.dynamicContent {
10 = LOAD_REGISTER
10.colPos.cObject = TEXT
10.colPos.cObject {
field = colPos
ifEmpty.cObject = TEXT
ifEmpty.cObject {
value.current = 1
ifEmpty = 0
}
}
20 = CONTENT
20 {
table = tt_content
select {
orderBy = sorting
where = colPos={register:colPos}
where.insertData = 1
}
}
90 = RESTORE_REGISTER
}
We used a modified version of that snippet to sneak in some more parameter values for the CONTENT object.
So we can hand over a data field pageUid, if that is not set we will use the uid of the current page. This will be overriden if the current or the target page is configured to show content from another page and finally we can trigger a slide with another data field.
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
}
}
20 = CONTENT
20 {
table = tt_content
slide = -1
slide.if.isTrue.field = slide
select {
includeRecordsWithoutDefaultTranslation = 1
orderBy = sorting
where = {#colPos}={register:colPos}
where.insertData = 1
pidInList.data = register:pageUid
pidInList.override.data = register:contentFromPid
}
}
90 = RESTORE_REGISTER
}
This enables us to make use of the <f:cObject> view helper while triggering additional parameters just by handing over some more values within the data array.
Related
I'm trying to use different Frontend-Layouts in TYPO3. So I'm using this fancy TypoScript:
page {
bodyTag = <body>
10= CASE
10.key.field=layout
# Standardtemplate
10.0 = TEMPLATE
10.0.template = FILE
10.0.template.file = fileadmin/template/content_template.html
10.0.workOnSubpart = DOCUMENT_BODY
# Variante 1:
10.1 = TEMPLATE
10.1.template = FILE
10.1.template.file = fileadmin/template/index_template.html
10.1.workOnSubpart = DOCUMENT_BODY
includeJSFooter {
jquery = fileadmin/template/js/jquery.js
bootstrap = fileadmin/template/js/bootstrap.min.js
app = fileadmin/template/js/app.js
}
includeCSS {
robotoFont = https://fonts.googleapis.com/css?family=Roboto:100,400
robotoFont.external = 1
robotoFont.media = all
bootstrapCore = fileadmin/template/css/bootstrap.min.css
bootstrapCore.media = all
}
}
This is not working yet. Every single page is completely. Only a white page appears. I'm using TYPO3 7.6.16. Is there any issue in my code above?
It think you are looking for this just place it in the PAGE-Element and rename the Path and also create some BackendLayouts named as value in layout 1. 2. 3. e.g. hope this will help:
10 = FLUIDTEMPLATE
10 {
file = fileadmin/templates/Page/Standard.html
partialRootPath = fileadmin/templates/Partials/
variables {
layout = CASE
layout {
key.field = backend_layout
key.ifEmpty.data = levelfield:-2, backend_layout_next_level, slide
1 = TEXT
1.value = startpage
2 = TEXT
2.value = subpage
3 = TEXT
3.value = subpagespecial
default = TEXT
default.value = subpage
}
content = CONTENT
content {
table = tt_content
select.orderBy = sorting
select.where = colPos=0
select.languageField = sys_language_uid
select.includeRecordsWithoutDefaultTranslation = 1
}
header = CONTENT
header {
table = tt_content
select.orderBy = sorting
select.where = colPos=1
select.languageField = sys_language_uid
select.includeRecordsWithoutDefaultTranslation = 1
}
content2 = CONTENT
content2 {
table = tt_content
select.orderBy = sorting
select.where = colPos=3
select.languageField = sys_language_uid
select.includeRecordsWithoutDefaultTranslation = 1
}
contentfull = CONTENT
contentfull {
table = tt_content
select.orderBy = sorting
select.where = colPos=2
select.languageField = sys_language_uid
select.includeRecordsWithoutDefaultTranslation = 1
}
}
}
Please add a default variant in the CASE object. It may be that pages which are created anew do not have a '0' in its 'layout' column.
Did you verify that the subpart markers are spelled correctly?
<!-- ###DOCUMENT_BODY### begin -->
Your HTML template
<!-- ###DOCUMENT_BODY### end -->
You could simplify your TypoScript template:
page {
10 = TEMPLATE
10.template = FILE
10.template.file = CASE
10.template.file {
key.field = layout
default = TEXT
default.value = fileadmin/template/content_template.html
1 = TEXT
value = fileadmin/template/index_template.html
}
10.workOnSubpart = DOCUMENT_BODY
}
In TYPO3 6.2 (just upgraded from 4.5) I have a TMENU with Images, using a cObject in NO to build the menu as desired.
It works in the main language, but in the second language's frontend, the images are not rendered - unless they are filled in in the second language's media field.
How do you force FILES to refer to the media field of the original language?
In my case, always. In other cases, a fallback solution may be desired.
temp.menu = COA
temp.menu {
wrap = <div class="teasermenu">|</div>
15 = HMENU
15 {
special = list
//special.value.cObject < temp.displayedpages
// recieves a list, such as:
special.value = 1,3,9
1 = TMENU
1 {
noBlur = 1
maxItems = 16
wrap = <ul>|</ul>
NO {
wrapItemAndSub = <li>|</li>
ATagBeforeWrap = 1
ATagParams = || || || || class="red" |*| |*|
stdWrap.cObject=COA
stdWrap.cObject{
10 = TEXT
10.field = nav_title // title
10.wrap = <strong class="teasermenu_header">|</span></strong>
20=FILES
20{
if{
isInList.field = uid
//value.cObject < temp.displayedpages_wimage
// receives another list, like:
// value = 3,9
}
references {
table=pages
fieldName=media
}
renderObj=IMAGE
renderObj{
file{
height=80
maxH=80
import.data=file:current:publicUrl
}
altText.field=title
titleText.field=title
}
}
}
}
}
}
}
PS there are many media field / FAL fallback related bugs on forge, e.g. this one. But I have a feeling this might be a simpler issue.
mergeIfNotBlank is gone now, the current solution (TYPO3 8.7) seems to be to set
$GLOBALS['TCA']['pages']['columns']['media']['config']['behaviour']['allowLanguageSynchronization'] = 1;
But based on https://forum.typo3.org/index.php/t/217033/-typo3-ug-freiburg-media-feld-in-den-seiteneigenschaften (thanks) there's this snippet. It also works with cropVariants:
temp.bgimg_wide = CONTENT
temp.bgimg_wide{
table = sys_file_reference
select{
pidInList = {$pids.pidHome}
where = tablenames='pages' AND fieldname='media'
orderBy = sorting_foreign
languageField = 0
selectFields = uid_local
max = 1
begin = 0
}
renderObj = FILES
renderObj{
files.stdWrap.field = uid
renderObj = IMG_RESOURCE
renderObj {
file {
import.data = file:current:uid
treatIdAsReference = 1
width = 1600
cropVariant = bgimg_wide
}
}
}
}
}
This works!
With TYPO3 CMS 7.6 you need to exclude field media of table pages from [FE][pageOverlayFields] as set in ~/typo3_src-7.6.10/typo3/sysext/core/Configuration/DefaultConfiguration.php, until it is solved - see forge issue https://forge.typo3.org/issues/65863
Write in your AdditionalConfiguration
$GLOBALS['TYPO3_CONF_VARS']['FE']['pageOverlayFields'] = 'uid,doktype,title,subtitle,nav_title,keywords,description,abstract,author,author_email,url,urltype,shortcut,shortcut_mode';
or in your Extension ext_localconf.php
$GLOBALS['TYPO3_CONF_VARS']['FE']['pageOverlayFields'] = str_replace(',media', '', $GLOBALS['TYPO3_CONF_VARS']['FE']['pageOverlayFields']);
Based on Urs' answer, here comes a slight variation.
lib.getCurrentPageMedia = CONTENT
lib.getCurrentPageMedia {
table = sys_file_reference
select{
pinInList = root, this
where = tablenames='pages' AND fieldname='media' AND uid_foreign=###pid###
orderBy = sorting_foreign
languageField = 0
selectFields = uid_local
max = 1
begin = 0
markers {
pid.data = TSFE:id
}
}
renderObj = TEXT
renderObj.stdWrap.field = uid
}
Fluid:
<f:image src="{f:cObject(typoscriptObjectPath:'lib.getCurrentPageMedia')}" alt="" width="400c" height="400c" treatIdAsReference="1" class="img-responsive" />
Advantage: you can define cropping, alt-text, etc. in your template.
You might want to try to set the TCA of the media field to l10n_mode => mergeIfNotBlank .
http://docs.typo3.org/typo3cms/TCAReference/Reference/Columns/Index.html#columns-properties-l10n-mode
Put this into the typo3conf/AdditionalConfiguration.php:
$TCA['pages']['columns']['media']['l10n_mode'] = 'mergeIfNotBlank';
Since this issue is from Februari, you've probably found a solution by now. I just ran into this issue and solved it by including:
$GLOBALS['TCA']['pages_language_overlay']['columns']['media']['l10n_mode'] = 'mergeIfNotBlank';
in my ext_tables.php
I'm using typoscript go get the first file out of a page. This works and is out of the documentation. But the documentation doesn't tell something about a fallback if no files are found.
lib.files = FILES
lib.files {
references {
table = pages
fieldName = media
}
file =
begin = 0
maxItems = 1
renderObj = TEXT
renderObj {
value = URL: {file:current:publicUrl}
insertData = 1
}
}
A naive .if.isNull failed at the first attpent. Is there a possibilty to define a fallback if the FILES-Object is empty?
Mh,
try to make a second object and check there if lib.files is filled with data.
__
UNTESTED
lib.files = FILES
lib.files {
references {
table = pages
fieldName = media
}
file =
begin = 0
maxItems = 1
renderObj = TEXT
renderObj {
value = URL: {file:current:publicUrl}
insertData = 1
}
}
lib.fileFallback = COA
lib.fileFallback {
10 < lib.files
20 = TEXT
20 {
value = Do something
stdWrap.if.isFalse.cObject < lib.fileFallback.10
}
}
I am using this technique often to slide through pages for slideshow objects.
Let me know, if it is working.
You should check the TypoScript Reference stdWrap.ifEmpty.
In your case the code should look like this
lib.files {
# ....
stdWrap.ifEmpty.cObject = IMAGE
stdWrap.ifEmpty.cObject{
file = fileadmin/.../my_image.png
}
# ....
}
You can use every cObject you want.
Check out Content Objects (cObject)
I have the following problem:
I am using typo3 4.7.7 and I am adding custom columns in the Backend. I am able to do taht by place a configuration array in the /typo3conf/extTables.php
$TCA["tt_content"]["columns"]["colPos"]["config"]["items"] = array (
"3" => array ("Border,"3"),
"2" => array ("Right","2"),
"1" => array ("Left","1"),
"0" => array ("Normal","0"),
"5" => array ("Central","5"),
"6" => array ("Border","6"),
"4" => array ("Footer","4")
);
Then set:
mod.SHARED.colPos_list=0,1,2,3,4,5,6
in the TSconfig.
It is working, I enjoy my new columns :), but there is a problem. I want to be able to use the css_styled_content to map my new columns to my html template. This is not possible, because the "get" constants of css_styled_content are hard coded and I am not able to use something like "content.getFooter". At the moment the only way I can get my content is like this:
...
page.10 = CONTENT
page.10.table = tt_content
page.10.select {
orderBy = sorting
where = colPos = 4
}
page.10.renderObj = COA
page.10.renderObj {
10 = TEXT
10.field = header
20 = TEXT
20.field = bodytext
}
...
This is a lot of code, so I was wondering if there is a way to "make" CSC recognize my new columns, so that I would be able to use "content.getMYCUSTOM_COLUMN_NAME".
P.S. I do not want to use templavoila and I found something in the source of CSC under /static/setup.txt :
# Clear out any constants in this reserved room!
styles.content >
# get content
styles.content.get = CONTENT
styles.content.get {
table = tt_content
select.orderBy = sorting
select.where = colPos=0
select.languageField = sys_language_uid
}
# get content, left
styles.content.getLeft < styles.content.get
styles.content.getLeft.select.where = colPos=1
# get content, right
styles.content.getRight < styles.content.get
styles.content.getRight.select.where = colPos=2
# get content, margin
styles.content.getBorder < styles.content.get
styles.content.getBorder.select.where = colPos=3
# get news
styles.content.getNews < styles.content.get
styles.content.getNews.select.pidInList = {$styles.content.getNews.newsPid}
# Edit page object:
styles.content.editPanelPage = COA
styles.content.editPanelPage {
10 = EDITPANEL
10 {
allow = toolbar,move,hide
label.data = LLL:EXT:css_styled_content/pi1/locallang.xml:eIcon.page
label.wrap = | <b>%s</b>
}
}
I then tried to add:
# get content, footer
styles.content.getFooter < styles.content.get
styles.content.getFooter.select.where = colPos=4
But it did not work.
you are on the right track. try to create your own Content Object:
temp.footer < styles.content.get
temp.footer.select.where = colPos=4
page = PAGE
page.100 < temp.footer
This is what I want to do: on a given page, I want to display all content elements of the first child page of a given page. I cannot simply use a shortcut page, because I need to display other content elements after the ones from the sub-page. How can I do this?
Here is a snippet of how I think I could do it, but I don't know how to build the select. Is there a better way?
# save current content
tmp.pagecontent < page.10.subparts.main-content
# clear the content of the main column
page.10.subparts.main-content >
# build a new object for this column as content-object-array
page.10.subparts.main-content = COA
page.10.subparts.main-content {
10 = CONTENT
10.table = tt_content
10.select {
# what should I put here?
}
# re-insert the normal pagecontent to the page
20 < tmp.pagecontent
Just add answer for other people.
First : specify the first sub page of current page.
Second : get content elements that you want of that sub page.
temp.content = COA
temp.content {
10 = CONTENT
10 {
table = pages
select {
pidInList.field = uid
orderBy = sorting ASC
max = 1
begin = 0
}
renderObj = COA
renderObj {
10 = CONTENT
10 {
table = tt_content
select {
languageField = sys_language_uid
pidInList.field = uid
orderBy = sorting
#where = colPos = 10
}
stdWrap.wrap = |
}
}
}
}
I finally succeed! Not sure though it is the best way. What do you think about it? Should I put the second select into userFunc too?
fileadmin/userfunc/mailArchive.php
<?php
class user_mailArchive {
function getFirstChild($content, $conf) {
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'uid', // SELECT ...
'pages', // FROM ...
'pid='.intval($conf['pid']), // WHERE...
'', // GROUP BY...
'sorting', // ORDER BY...
'1' // LIMIT ...
);
$row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
if ($row) {
return $row['uid'];
}
else {
return '';
}
}
}
TS template
# fill the content of the main-column to a tmp.object
tmp.pagecontent < page.10.subparts.main-content
# clear the content of the main column
page.10.subparts.main-content >
includeLibs.mailArchive= fileadmin/userfunc/mailArchive.php
# build a new object for this column as content-object-array
page.10.subparts.main-content = COA
page.10.subparts.main-content {
10 = CONTENT
10 {
table = tt_content
select {
pidInList.cObject = USER
pidInList.cObject {
userFunc = user_mailArchive->getFirstChild
# parent page ID
pid = 139
}
orderBy = sorting
}
}
# re-insert the normal pagecontent to the page
20 < tmp.pagecontent
}