TYPO3: Show content from a fixed page if there’s no content on current page - typo3

I would like to show content from a fixed page if there’s no content on current page.
An example: On the mainpage (pid=58) In the right col (colPos=31) I have a news plugin with the latest item. On subpages, it’s possible to insert content in the right col (colPos=31). It could be images,text etc. BUT, if the right col is empty I would like to show the news plugin from the mainpage as a fallback option.
This is my TypoScript, but it doesn’t work. Default content from mainpage are not showed, if there's no content from current page.
lib.rightCol-1 = COA
lib.rightCol-1 {
10 = COA
10 {
## Get content from current page.
10 = COA
10 < styles.content.get
## Get content from colPos 31
10.select.where = colPos=31
if.isTrue.current = 1
20 = CONTENT
20 {
## IF no content on current page show content from mainpage
stdWrap.if.isTrue.current = 1
stdWrap.if.negate = 1
table = tt_content
select {
## Get content from mainpage
pidInList = 58
where = colPos=31
orderBy = sorting
languageField = sys_language_uid
}
}
}
}

This can be done using stdWrap.override. If stdWrap.override returns something non-empty, this value replaces the normal value stdWrap would return. In your case, this could look like this:
# Fetch the default content from the mainpage with id 58
lib.rightCol-1 = CONTENT
lib.rightCol-1 {
table = tt_content
select {
pidInList = 58
where = colPos=31
orderBy = sorting
languageField = sys_language_uid
}
# override the content from page 58 with content from the current page,
# but only if there is content on this page
stdWrap.override.cObject = CONTENT
stdWrap.override.cObject {
table = tt_content
select {
pidInList = this
where = colPos=31
orderBy = sorting
languageField = sys_language_uid
}
}
}
You can also create the following behaviour:
If there is content on the current page, show it.
Else, walk up the rootline and take the content from the first page that has content in the column.
If there is no such page, take the content from the "mainpage".
This can be done by simply setting slide = -1 to the second CONTENT-Object.

Thanks for answer but I couldn't get it to work. Instead this worked:
lib.rightCol-1 = CONTENT
lib.rightCol-1 < styles.content.get
lib.rightCol-1.select.where = colPos=31
lib.rightCol-1 {
stdWrap.ifEmpty.cObject = CONTENT
stdWrap.ifEmpty.cObject {
table = tt_content
select {
pidInList = 58
orderBy = sorting
where = colPos = 31
languageField = sys_language_uid
}
}
}

Related

Typoscript records not translated content

I have a piece of typoscript code, it works nice for the main language but does not translate?
20 = RECORDS
20 {
source.data = field:pid
tables = pages
conf.pages = TEXT
conf.pages.field = title
wrap = <li class="text-li"><h2>|</h2>
}
How to get the translated "title" field from database?
p.s. This code is working with fallbackType: fallback, but not with the current fallbackType: free
We want to keep free enabled because the site is already filled by the editors in this manner
Thanks to Thomas Löffler:
20 = CONTENT
20 {
table = pages
select {
where = (l10n_parent={field:pid} AND sys_language_uid={field:sys_language_uid}) OR (uid={field:pid})
where.insertData = 1
}
slide = -1
renderObj = COA
renderObj {
10 = TEXT
10.stdWrap.field = title
10.stdWrap.wrap = <li class="text-li"><h2>|</h2>
}
}

TYPO3 10 <f:cObject/> does NOT render first content-element from tt_content table after clearing cache

I am currently facing the issue, that when I fetch content from a specific page via typoscript, I only get the full content after the second pageload if I have deleted all caches before. The first content element is not rendered at all (seems to be ignored).
Here is my Typoscript:
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
}
}
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
}
stdWrap {
dataWrap = {register:wrap}
required = 1
}
}
90 = RESTORE_REGISTER
}
This is how I render the content in fluid:
<f:cObject typoscriptObjectPath="lib.dynamicContent" data="{pageUid: '41', colPos: '1'}" />
The output from the first content element after clearing the cache is on the first pageload: <div />. When I reload the page, I get the full content from the page.
I already checked the database queries which are executed, but they are always the same and return the correct results.
System:
TYPO3 10.4.8
PHP 7.3
You should remove the stdWrap part, which contains a wrap, that should be created via plain HTML in your Fluid template instead.
Im not 100% sure, but I guess the required check within that stdWrap section disables the content as well, since it might be checked before the actual content has been rendered.

TYPO3 Hide & Replace Pagetitle in Breadcrumb

I have a little problem with my navigation and couldn't get it work...I got on every page a breadcrumb navigation which shows the page tree until the current page.
So far so good but when I go to the details page of my news I got the following tree Home > Newest > Article. I don't want to have the page title Article here because every other news would have this tree. Instead of the pagetitle I want to have the news title so I modified my navigation like this:
30 = HMENU
30 {
special = rootline
special.range = 0 | -1
1 = TMENU
1 {
stdWrap.dataWrap = <p>{ date : d.m.Y } ::: |
NO = 1
NO {
wrapItemAndSub = | >
stdWrap.htmlSpecialChars = 1
}
CUR = 1
CUR.allWrap = | </p>
stdWrap.append = RECORDS
stdWrap.append {
if.isTrue.data = GP:tx_news_pi1|news
tables = tx_news_domain_model_news
source.data = GP:tx_news_pi1|news
source.intval = 1
conf.tx_news_domain_model_news = TEXT
conf.tx_news_domain_model_news {
field = title
htmlSpecialChars = 1
}
}
}
}
And now the problem: when I click go on a page which is hidden in menus the breadcrumb looks like this Home >. Obviously the last page isn't displayed and this should be solved but I don't know how to do it.
At least I tried something with this in some combinations but cant't get it work
if {
value = 46
equals.field = uid
excludeUidList = 46 //includeNotInMenu = 1
}
When adding includeNotInMenu = 1 under the special.range hidden pages are shown in the breadcrumb title but then the breadcrum in news looks like this Home > Newest > Article NewsTitle and I don't want to have this 'Article' in it. Hope someone of you can help me!
first:
not displaying the current page is ok only for the news-detail page. so use a condition to realize it:
[page|uid = 123]
30.30.special.range = 1|-2
[global]
second:
add the current news title after the menu. the handling is a littel bit easier.
30.40 = RECORDS
30.40 {
tables = tx_news_domain_model_news
source.data = GP:tx_news_pi1|news
source.intval = 1
conf.tx_news_domain_model_news = TEXT
conf.tx_news_domain_model_news {
field = title
htmlSpecialChars = 1
}
}
therefore you might need to change the wrap. either split it or (better) give it an additional COA level.
and so the news title only is neccessary on your detail page you put that code into the condition.
Alternatives:
you can use .stdWrap.if to modify the range of the breadcrumb and the display of the news title, but with the TS-condition you have a smaller typoscript for normal pages (faster rendering).
You even need no condition for the tx_news_pi1|news parameter, as the detail page normaly would not show anything (except an error)
For example (since Ext news 7.2) to hide News Detail page in the breadcrumb..
Home > News > News Detail > Article name
page.10.dataProcessing {
100 = TYPO3\CMS\Frontend\DataProcessing\MenuProcessor
100 {
special = rootline
special.range = 0|-1
includeNotInMenu = 1
as = breadcrumb
}
110 = GeorgRinger\News\DataProcessing\AddNewsToMenuProcessor
110.menus = breadcrumb
}
[page["uid"] == {$pages.newsDetail}]
page.10.dataProcessing.100.special.range = 0|-2
[END]
Results in
Home > News > Article name

Add image to menu/sitemap element in TYPO3

I am using TYPO3 4.7 (Upgrading is not an option). Can I customize the Menu/Sitemap element to include the first image on each linked page?
So In this case I'd be using:
tt_content.menu.20.1.1.NO
First of all you really should update the site as there are a lot security issues which can do harm to your/your customer's website.
Back to your question: Of course you can render any content inside a menu as well!
lib.menu = HMENU
lib.menu {
wrap = <ul>|</ul>
1 = TMENU
1.NO {
wrapItemAndSub = <li>|</li>
after.cObject = CONTENT
after.cObject {
table = tt_content
select {
pidInList.field = uid
}
renderObj = COA
renderObj {
10 = TEXT
10.field = header
10.htmlSpecialChars = 1
20 = TEXT
20 {
field = image
split {
token = ,
cObjNum = 1
1 {
10 = IMAGE
10 {
file {
import=uploads/pics/
import.current = 1
width = 170
height = 100
}
}
}
}
}
}
}
}
}
tt_content.menu.20.1.1.NO < lib.menu.1.NO
To be honest: the part with the image is untested as I don't have any non-FAL (since 6.0) installation anymore where I could test it.

TYPO3 TypoScript: Display a list of subpages with content on parent page

I am trying to create an archive page that displays a list of subpages, similar to WordPress but display the parent's subpages instead of posts. I want the archive page to include the following from the subpage:
Title
First image
First 150 words of regular text element
At the moment I can display a page title, but that's where I got stuck. I am placing the code in a sub template. Here is the code.
lib.portfoliolist = CONTENT
lib.portfoliolist.table = pages
lib.portfoliolist.select {
pidInList = this
}
lib.portfoliolist.renderObj = COA
lib.portfoliolist.renderObj {
stdWrap.wrap = <div class="project">|</div><hr />
10 = TEXT
10 {
field = title
wrap = <h2>|</h2>
10.typolink.parameter.field = uid
}
}
If it helps, all of the images are within the fileadmin/user_upload/ directory, and this is my page structure:
Root
Home
About
Project Portfolio
Project 1
Project 2
Blog
Contact Us
Seems like I figured it out myself, all I had to do was call for content in a separate query. For those that are looking to achieve something similar, here is the code I used to help you out.
lib.portfoliolist = CONTENT
lib.portfoliolist.table = pages
lib.portfoliolist.select {
orderBy = sorting ASC
}
lib.portfoliolist.renderObj = COA
lib.portfoliolist.renderObj {
stdWrap.allWrap = <div class="row">|</div>
stdWrap.wrap = <div class="project col-lg-6 col-md-6 col-sm-12 col-xs-12">|</div>
10 = TEXT
10 {
field = title
wrap = <h2>|</h2>
typolink.parameter.field = pages.uid
}
20 = CONTENT
20 {
table = tt_content
select {
pidInList.field = uid
selectFields = header, bodytext
orderBy = sorting ASC
}
renderObj = COA
renderObj {
30 = TEXT
30.value {
field = bodytext
wrap = <div>|</div>
}
}
}
}