TypoScript / Typo3: How to build sub-content of a page using header_link value? - typo3

How can I build a sub-content (nested content) of a page using typoscript with reference to the parent's header_link field?
Desired output is something like:
<h1>Title of parent</h1>
<p class="prt">Body of parent</p>
<h3>Title of Child</h3>
<p class="cld">Contents of child</p>
Sample of my Typoscript:
temp.myParentVal = CONTENT
temp.myParentVal {
table = tt_content
select {
begin = 1
orderBy = sorting
where = (colPos = 1)
}
renderObj = COA
renderObj {
10 = TEXT
10 {
required = 1
wrap = <h1> | </h1>
stdWrap.field = header
}
20 = TEXT
20 {
required = 1
wrap = <p class="prt"> | </p>
stdWrap.field = bodytext
}
# #
# WHAT SHOULD I DO HERE TO SHOW THE CHILD CONTENT OF THIS PAGE #
# (REFERENCED BY header_link FIELD IN THE PARENT'S ROW), #
# WHICH HAS THE FORMAT OF <child_pid#child_uid>, EG.'11#28' #
# #
stdWrap.wrap = <div> | </div>
}
I would like to make use of parent's header_link field value to generate the content for the child. (I'm using TYPO3 v. 6.2.14)

You can use a nested CONTENT element and split the header_link via Regex like this:
30 = CONTENT
30 {
table = tt_content
select {
uidInList {
field = header_link
stdWrap.replacement.10 {
search = /^.+#/
replace =
useRegExp = 1
}
}
pidInList {
field = header_link
stdWrap.replacement.10 {
search = /#.+$/
replace =
useRegExp = 1
}
}
}
renderObj = COA
renderObj {
10 = TEXT
10.value {
required = 1
wrap = <h3> | </h3>
field = header
}
20 = TEXT
20.value {
required = 1
wrap = <p class="cld"> | </p>
field = bodytext
}
}
}
Also, I wanted to suggest that you use the field property directly on the TEXT elements (which works). But I looked it up in the docs:
stdWrap properties are available on the very rootlevel of the object. This is non-standard! You should use these stdWrap properties consistently to those of the other cObjects by accessing them through the property "stdWrap".
https://docs.typo3.org/typo3cms/TyposcriptReference/ContentObjects/Text/Index.html
As value is a stdWrap object, you could use it as I did above.

Related

How to put out a record with all categorie-titles connected to it

On a website, various records are to be output as teasers. Each record is assigned to one or more categories. In the teasers, the titles of all categories assigned to the respective record should be displayed.
I tried this with a Typoscript (see below), in which I linked the database query of tt_content via a JOIN with sys_category and sys_category_record_mm.
But now for records that have multiple categories assigned to them, the corresponding teasers are output multiple times, i.e. once per category.
Fluid:
<f:if condition="{data.tx_mask_cnt_mag_teaser_records}">
<f:for each="{data.tx_mask_cnt_mag_teaser_records}" as="data_item">
<f:cObject typoscriptObjectPath="lib.magteaser" data="{dsuid: data_item.uid, recid: data_item.records, reclimit: 2, tstype: 1, syscats: data.tx_mask_cnt_mag_teaser_cats}" />
</f:for>
</f:if>
Typoscript:
lib.magteaser = COA
lib.magteaser {
wrap = |
5 = LOAD_REGISTER
5 {
dTstype.data = field:tstype // Different Teaser-Types
dSyscats.data = field:syscats // List of all categories to consider
}
10 = CONTENT
10 {
table = tt_content
select {
pidInList = 13 // Folder in which the records are stored
uidInList.data = field:recid
recursive = 2
selectFields.dataWrap = *, FIND_IN_SET(`tt_content`.`uid`,'{field:recid}') AS reclist_sortby
join = sys_category_record_mm ON (sys_category_record_mm.uid_foreign = tt_content.uid) JOIN sys_category ON (sys_category_record_mm.uid_local = sys_category.uid)
where = tt_content.hidden=0
where = tt_content.CType='mask_cnt_textpic_uni'
where.data = field:syscats
# where.intval = 1
where.wrap = sys_category_record_mm.uid_local IN (|)
orderBy = reclist_sortby
}
renderObj = COA
renderObj {
5 = LOAD_REGISTER
5 {
# Count variable for a CASE (see below) to format the first data record differently from the remaining data records.
dsCounter.stdWrap.dataWrap = {register:dsCounter} + 1
dsCounter.prioriCalc = intval
}
10 = CASE
10 {
key.data = register:dTstype
default = COA
default {
wrap = <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 col-xl-6 magteaser-std">|</div>
[...]
}
# 1 Titelbild und 2 Standard-Teaser
1 = COA
1 {
wrap = <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 col-xl-6 magteaser-std">|</div>
[...]
}
# 1 Top-Teaser und 2 Standard-Teaser
2 = COA
2 {
10 = CASE
10 {
key.data = register:dsCounter
# Standard-Teaser
default = COA
default {
wrap = <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 col-xl-6 magteaser-std">|</div>
10 = TEXT
10 {
wrap = Kategorie (def): |
value.dataWrap = {field:title}
}
[...]
}
# Top-Teaser
1 = COA
1 {
wrap = <div class="col-12 magteaser-top">|</div>
10 = TEXT
10 {
wrap = Kategorie (1): |
value.dataWrap = {field:title}
}
[...]
}
}
}
}
}
}
}
Does anyone have a tip for me on how to solve the problem?
Many thanks in advance for your help!
Typo3 V.9.5.8
With the join you generate a matrix, with a 'record' for each combination.
The correct handling would be to handle the mutiple categories in the renderObj:
build a part where all categories for this tt_content record are printed.
conceptual structure:
10 = CONTENT
10 {
table = tt_content
select {
:
// without JOIn
:
}
renderObj = COA
renderObj {
:
50 = CONTENT
50 {
table = sys_categories
SELECT {
join = sys_category_record_mm ON (sys_category_record_mm.uid_foreign = ###CONTENT_UID###) AND (sys_category_record_mm.uid_local = sys_category.uid)
markers {
// context is current tt_content record:
CONTENT_UID.field = uid
}
}
renderObj = TEXT
renderObj.field = title
renderObj.wrap = || ,|
}
}
}

TYPO3 - simpler way, rendering content from colPos into Fluidtemplate?

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.

Typoscript operators - Value of filelink referencing to another one

I've set up the Typoscript below, but the last line doesn't work.
I want 20.filelink to have the same content as 10.filelink (the real code is more complex and that bit is redundant).
lib.test = COA
lib.test {
10 = TEXT
10.value = A value
10.filelink {
path = fileadmin/path/
target = blank
stdWrap.wrap = <li>|</li>
}
20 = TEXT
20.if.isFalse.data = subheader
20.value = Another value
20.filelink =< lib.test.10.filelink
}
Copying (with the < operator) works, but not =< as stated.
I've also tried without the lib.test. or with just = but without any success.
Is what I want to do possible?
What did I not understand about operators?
you should put it out of the curly brackets :
lib.test = COA
lib.test {
10 = TEXT
10.value = A value
10.filelink {
path = fileadmin/path/
target = blank
stdWrap.wrap = <li>|</li>
}
20 = TEXT
20.if.isFalse.data = subheader
20.value = Another value
}
lib.test.10.filelink =< lib.test.20.filelink
I figured out what I did not understand. Apparently, you can only copy or reference Content Objects.
The answer then is to reference the entire object, and to modify and add what needs changing. In this case it would be:
lib.test = COA
lib.test {
10 = TEXT
10.value = A value
10.filelink {
path = fileadmin/path/
target = blank
stdWrap.wrap = <li>|</li>
}
20 = < lib.test.10
20.if.isFalse.data = subheader
20.value = Another value
}

Refer to media field of original language in TYPO3

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

The detailed view of the last item of a list build by TypoScript is always blank

Here's the TypoScript code.
lib.membersList = CONTENT
lib.membersList{
table = tt_address
select{
pidInList = {$membersStorageFolder}
orderBy = zip, last_name
}
wrap = <div class="membersList">|</div>
renderObj = COA
renderObj{
10 = FLUIDTEMPLATE
10{
file = fileadmin/templates/ext/memberslist/templates/membersList.html
variables{
portrait = IMAGE
portrait{
file.import = uploads/pics/
file.import {
field = image
listNum = 0
}
file.height = 105
file.width = 105c
stdWrap.typolink{
parameter = {$membersPageId}
additionalParams.dataWrap = &ts_addresslist[showUid]={field:uid}
#returnLast = url
# The cache hash is needed to display the right content, since we are not running as USER_INT
useCacheHash = 1
}
}
lastName = TEXT
lastName.field = last_name
lastName.typolink{
parameter.data = TSFE:id
additionalParams.dataWrap = &ts_addresslist[showUid]={field:uid}
# The cache hash is needed to display the right content, since we are not running as USER_INT
useCacheHash = 1
}
firstName = TEXT
firstName.field = first_name
firstName.typolink{
parameter.data = TSFE:id
additionalParams.dataWrap = &ts_addresslist[showUid]={field:uid}
# The cache hash is needed to display the right content, since we are not running as USER_INT
useCacheHash = 1
}
title = TEXT
title.field = title
organisation = TEXT
organisation.field = company
country = TEXT
country.field = country
city = TEXT
city.field = city
}
}
}
stdWrap.override.cObject = CONTENT
stdWrap.override.cObject{
table = tt_address
select {
andWhere.data = GP:ts_addresslist|showUid
# Make sure there is no SQL injection!
andWhere.intval = 1
andWhere.wrap = uid=|
orderBy = last_name ASC
pidInList = {$membersStorageFolder}
}
wrap = <div class="membersDetail">|</div>
renderObj = FLUIDTEMPLATE
renderObj{
file = fileadmin/templates/ext/memberslist/templates/membersDetail.html
variables{
portrait = IMAGE
portrait{
file.import = uploads/pics/
file.import {
field = image
listNum = 0
}
file.height = 105
file.width = 105c
}
lastName = TEXT
lastName.field = last_name
firstName = TEXT
firstName.field = first_name
title = TEXT
title.field = title
organisation = TEXT
organisation.field = company
country = TEXT
country.field = country
city = TEXT
city.field = city
detail = TEXT
detail.field = description
}
}
renderObj.stdWrap.append = TEXT
renderObj.stdWrap.append{
value = << Back to list
typolink.parameter = {$membersPageId}
}
}
stdWrap.override.if {
isTrue.data = GP:ts_addresslist|showUid
isTrue.intval = 1
}
}
Everything is working fine. The list is displayed as it should. The detailed view also except for the last item. When I click on it, the detailed view displays a blank page. No information, as if the query fetched nothing.
Here are the templates, very simple though.
membersList.html
<section>
{portrait -> f:format.raw()}
<div class="memberDetail">
<h1>{lastName -> f:format.raw()} {firstName -> f:format.raw()}</h1>
<h2>{title} - {organisation}</h2>
<h3>{country} - {city}</h3>
</div>
</section>
membersDetail.html
<section>
{portrait -> f:format.raw()}
<div class="memberDetail">
<h1>{lastName} {firstName}</h1>
<h2>{title} - {organisation}</h2>
<h3>{country} - {city}</h3>
</div>
<div class="bio">
{detail}
</div>
</section>
Your code looks right so far. For debugging purpose add it directly to page object.
page.38388383 = CONTENT
page.38388383 {
table = tt_address
select{
pidInList = {$membersStorageFolder}
orderBy = zip, last_name
}
wrap = <div class="membersList">(|)</div>
renderObj = COA
renderObj{
10 = TEXT
10.field = uid
10.wrap = (|),
}
}
With this, you should get a comma separated list of all tt_address records without sideeffects. If that does not work, check on database level if everything is correct. Perhaps you some trouble with language, workspace or so...?
If this works like expected, you can replace your renderObj with this one and see what happens.
If expect that there is no crazy loop effect - but some CMS sideeffects (like missing rights, language, workspace version etc.).