My manually built TYPO3 lightbox isn't working properly - typo3

In a COA, I have this TypoScript to add an image linked to a larger copy of itself. But the Javascript plugin I'm using (Colorbox) isn't able to resize the image properly.
20 = CONTENT
20 {
wrap = <div class="lightbox clearfix">|</div>
required = 1
table = tt_content
select.languageField = sys_language_uid
select.where = colPos = 2
select.selectFields = bodytext,image,header
renderObj=COA
renderObj{
10 = FILES
10 {
required = 1
references {
table = tt_content
fieldName = image
}
renderObj = IMAGE
renderObj {
file.import.data = file:current:originalUid // file:current:uid
file.width=300c
file.height=300c
imageLinkWrap = 1
imageLinkWrap {
enable = 1
width = 1600m
height = 1600m
JSwindow = 0
linkParams.ATagParams {
// title.data =
dataWrap = class = "lightbox-group" title="{file:current:description}"
}
}
}
}
}
}
What's up?

Here's the correct TypoScript. I'm sharing it because it is a legacy weirdness others might stumble upon too.
You have to set imageLinkWrap.directImageLink = 1, else imageLinkWrap won't deliver the image itself, but a HTML page containing that image!
20 = CONTENT
20 {
wrap = <div class="lightbox clearfix">|</div>
required = 1
table = tt_content
select.languageField = sys_language_uid
select.where = colPos = 2
select.selectFields = bodytext,image,header
renderObj=COA
renderObj{
10 = FILES
10 {
required = 1
references {
table = tt_content
fieldName = image
}
renderObj = IMAGE
renderObj {
file.import.data = file:current:originalUid // file:current:uid
file.width=300c
file.height=300c
imageLinkWrap = 1
imageLinkWrap {
enable = 1
width = 1600m
height = 1600m
directImageLink = 1
JSwindow = 0
linkParams.ATagParams {
// title.data =
dataWrap = class = "lightbox-group" title="{file:current:description}"
}
}
}
}
}
}

Related

How to get first image in tt_content for meta og:image

I'm trying to fetch the first existing image in tt_content to be used in Open Graph (og:image) if any images in tt_content.
page.headerData {
1 = COA
1 {
10 = FILES
10 {
references {
table = tt_content
uid.field = uid
fieldName = image
}
renderObj = TEXT
renderObj {
typolink {
parameter.data = file:current:publicUrl
forceAbsoluteUrl = 1
returnLast = url
}
wrap = |,
}
stdWrap {
listNum = 0
# Use logo image if none is available
ifEmpty.cObject = TEXT
ifEmpty.cObject.typolink {
parameter = typo3conf/ext/my_ext/Resources/Public/Images/logo.png
forceAbsoluteUrl = 1
returnLast = url
}
wrap = <meta property="og:image" content="|">
}
}
}
}
The code above only returns the fallback (logo). Great for pages and tt_content without images, but I would expect different from pages with image(s) in tt_content.
I report here the nice snippet found on https://docs.typo3.org/m/typo3/docs-snippets/master/en-us/2014/Index.html#add-facebook-open-graph-og-image-metatags-for-content-elements-with-typo3-6-0-and-fal
I simplified it a bit; hope it is not too much simplified but it should work:
page.headerData.200 = CONTENT
page.headerData.200 {
table = tt_content
select {
where = {#colPos}=0
selectFields = uid
}
renderObj = FILES
renderObj {
references {
table = tt_content
uid.field = uid
fieldName = image
}
maxItems = 1
renderObj = TEXT
renderObj {
data = file:current:publicUrl
stdWrap {
wrap = <meta name="og:image" content="|" >
}
}
}
}
Here is #riccardo-de-contardi's snippet with a fallback
page.headerData.1569221029 = CONTENT
page.headerData.1569221029 {
table = tt_content
select {
where = {#colPos}=0
selectFields = uid
}
renderObj = FILES
renderObj {
references {
table = tt_content
uid.field = uid
fieldName = image
}
maxItems = 1
renderObj = TEXT
renderObj {
data = file:current:publicUrl
stdWrap {
wrap = |,
}
}
}
stdWrap {
listNum = 0
# Use logo image if none is available
ifEmpty.cObject = TEXT
ifEmpty.cObject.typolink {
parameter = typo3conf/ext/my_ext/Resources/Public/Images/logo.png
forceAbsoluteUrl = 1
returnLast = url
}
wrap = <meta property="og:image" content="|">
}
}

I want to override in typoscript CONTENT or renderObj with noting

I have a little problem, the following code works, but to not show what I do not want to display, I'm forced to put style =" display: none " with invalid HTML code, because I'm in <ul> <li> ... </ ul>. How could I not display anything at all?
40 = CONTENT
40 {
table = tt_content
select {
orderBy = sorting
pidInList.field = uid
where = {#colPos}=99 and deleted = 0 and hidden = 0
}
renderObj = COA
renderObj {
20 = TEXT
20.stdWrap.field = header
20.stdWrap.wrap = <b>|</b>
# OVERRIDE for <ul><li> ...
20.stdWrap.wrap.override = <span style="display:none">|</span>
20.stdWrap.wrap.override.if.value = 1
20.stdWrap.wrap.override.if.equals.dataWrap = {register:typeOfMenu}
30 = TEXT
30.stdWrap.field = bodytext
30.stdWrap.wrap = <i>|</i>
# OVERRIDE for <ul><li> ...
30.stdWrap.wrap.override = <span style="display:none">|</span>
30.stdWrap.wrap.override.if.value = 1
30.stdWrap.wrap.override.if.equals.dataWrap = {register:typeOfMenu}
40 = FILES
40 {
references {
table = tt_content
uid.data = field:uid
fieldName = image
}
begin = 0
maxItems = 1
renderObj = IMAGE
renderObj {
file {
import.data = file:current:originalUid // file:current:uid
#width = 232c
#height = 145c
}
required = 1
wrap = <div class="img-wrap">|</div>
}
}
# OVERRIDE for <ul><li> ...
40.stdWrap.wrap.override = <span style="display:none">|</span>
40.stdWrap.wrap.override.if.value = 1
40.stdWrap.wrap.override.if.equals.dataWrap = {register:typeOfMenu}
}//COA
}//CONTENT
In fact, I tried a lot of stuff before resigning myself to <span style =" display: none "> | </ span>, do you have a better solution?
Best regards
Did you try these propositions?
40.renderObj.40.if {
value = 1
equals.dataWrap = {register:typeOfMenu}
}
or
40.renderObj.40.stdWrap.if {
value = 1
equals.dataWrap = {register:typeOfMenu}
}
if that's not working you've to check if the register is filled with any data, you can check that just by rendering it too in 40.renderObj.50:
40.renderObj.50 = TEXT
40.renderObj.50.data = {register:typeOfMenu}
As it seems that {register:typeOfMenu} is defined outside that CONTENT and you want to render the whole block only if {register:typeOfMenu}=1 you could also note it like this:
40 = CONTENT
40 {
table = tt_content
select {
orderBy = sorting
pidInList.field = uid
where = {#colPos}=99 and deleted = 0 and hidden = 0
}
renderObj = COA
renderObj {
20 = TEXT
20.stdWrap.field = header
20.stdWrap.wrap = <b>|</b>
30 = TEXT
30.stdWrap.field = bodytext
30.stdWrap.wrap = <i>|</i>
40 = FILES
40 {
references {
table = tt_content
uid.data = field:uid
fieldName = image
}
begin = 0
maxItems = 1
renderObj = IMAGE
renderObj {
file {
import.data = file:current:originalUid // file:current:uid
#width = 232c
#height = 145c
}
required = 1
wrap = <div class="img-wrap">|</div>
}
}
}//COA
stdWrap.if {
value = 1
equals.dataWrap = {register:typeOfMenu}
}
}//CONTENT
Sorry, but I did not put all the code, there was before a COA. Now, thanks to your advice I have solved the problem. Here is the complete code:
NO {
doNotLinkIt = 1
stdWrap.cObject = COA
stdWrap.cObject {
10 = TEXT
10.wrap = <h1>|</h1>
10.field = nav_title // title
10.typolink.parameter.field = uid
# OVERRIDE for <ul><li> ...
10.wrap.override = <li class="laclasse">|
10.wrap.override.if.value = 1
10.wrap.override.if.equals.dataWrap = {register:typeOfMenu}
40 = CONTENT
40 {
table = tt_content
select {
orderBy = sorting
pidInList.field = uid
where = {#colPos}=99 and deleted = 0 and hidden = 0
}
renderObj = COA
renderObj {
20 = TEXT
20.stdWrap.field = header
20.stdWrap.wrap = <b>|</b>
30 = TEXT
30.stdWrap.field = bodytext
30.stdWrap.wrap = <i>|</i>
40 = FILES
40 {
references {
table = tt_content
uid.data = field:uid
fieldName = image
}
begin = 0
maxItems = 1
renderObj = IMAGE
renderObj {
file {
import.data = file:current:originalUid // file:current:uid
#width = 232c
#height = 145c
}
required = 1
#wrap = <div class="img-wrap">|</div>
titleText.data = page:subtitle
altText.data = page:subtitle
stdWrap.typolink.parameter.data = leveluid:0
}
}
}//COA
}//CONTENT
}//COA
# OVERRIDE for <ul><li> ...
stdWrap.cObject.40.if {
value = 1
equals.dataWrap = {register:typeOfMenu}
negate = 1
}
Thanking you,
Best regards

Fallback image in typoscript

I have the following menu-type, which works correctly for the main-part.
However, i want to add a fallback image, if no image is found.
tt_content.menu {
20 {
108 = HMENU
108 {
special = directory
special.value.field = pages
1 = TMENU
1.wrap = <div class="special_menu">|</div>
1.NO {
doNotLinkIt = 1
stdWrap.cObject = COA
stdWrap.cObject {
10 = FILES
10 {
references {
table = pages
fieldName = media
}
renderObj = IMAGE
renderObj {
file {
width = 263c
height = 155c
maxW = 263c
maxH = 155c
import.data = file:current:publicUrl
# if file:current:publicUrl is empty, use default image
if.isFalse = fileadmin/my/path/to/image.jpg
}
altText.field = title
imageLinkWrap = 1
imageLinkWrap {
enable = 1
typolink.parameter.field = uid
}
}
stdWrap.wrap = <div class="menu10_bild">|</div>
}
20 = TEXT
20.field = title
20.typolink.parameter.field = uid
20.wrap = <div class="menu10_text">|
30 = TEXT
30.field = abstract
30.wrap = <p>|</p></div><div class="w-clearfix"> </div>
}
}
}
}
}
for some reason, it just ignores the line. Can someone help me with that?
You should check the TypoScript Reference stdWrap.ifEmpty.
In your case the code should look like this
tt_content.menu {
20 {
108 {
1.NO {
stdWrap.cObject {
10 = FILES
10 {
# ....
stdWrap.ifEmpty.cObject = IMAGE
stdWrap.ifEmpty.cObject{
file = fileadmin/.../my_image.png
}
# ....
}
}
}
}
}
}
You can use every cObject you want.
Check out Content Objects (cObject)
Try this:
tt_content.menu {
20 {
108 = HMENU
108 {
special = directory
special.value.field = pages
1 = TMENU
1.wrap = <div class="special_menu">|</div>
1.NO {
doNotLinkIt = 1
stdWrap.cObject = COA
stdWrap.cObject {
# default image
value = fileadmin/my/path/to/image.jpg
10 = FILES
10 {
references {
table = pages
fieldName = media
}
renderObj = IMAGE
renderObj {
file {
width = 263c
height = 155c
maxW = 263c
maxH = 155c
import.data = file:current:publicUrl
}
altText.field = title
imageLinkWrap = 1
imageLinkWrap {
enable = 1
typolink.parameter.field = uid
}
}
stdWrap.wrap = <div class="menu10_bild">|</div>
}
20 = TEXT
20.field = title
20.typolink.parameter.field = uid
20.wrap = <div class="menu10_text">|
30 = TEXT
30.field = abstract
30.wrap = <p>|</p></div><div class="w-clearfix"> </div>
}
}
}
}
}

alt/title attributes in img-tag in typo3

I use the following Typoscript to get a menu of pages with images from respective page resource.
How can i get the page-title (or page-description etc.) to the images alt and/or title-tags?
tt_content.menu.20.4 >
tt_content.menu.20.4 = COA
tt_content.menu.20.4 {
wrap = <div>|</div>
10 = HMENU
10 {
special = directory
special.value.field = pages
1 = TMENU
1 {
noBlur = 1
NO = 1
NO {
stdWrap >
stdWrap {
cObject = COA
cObject {
10 = FILES
10 {
references {
table = pages
uid.data = field = uid
fieldName = media
data = levelmedia:-1, slide
treatIdAsReference = 1
listNum = 0
}
renderObj = IMG_RESOURCE
renderObj {
file.import.data = file:current:publicUrl
file.maxW = 100
file.maxH = 60
required = 1
}
stdWrap.wrap = <img src="|" title="???pagetitle???" alt="???pagetitle???">
}
}
}
wrapItemAndSub = <div>|</div>
}
}
}
}
Have you tried it with dataWrap?
i think it could be something like this
stdWrap.dataWrap = <img src="|" title="{field:title}" alt="{field:title}">
or maybe...
stdWrap.dataWrap = <img src="|" title="{page:title}" alt="{page:title}">
this works for me now
cObject = COA
cObject {
10 = FILES
10 {
references {
table = pages
uid.data = field = uid
fieldName = media
data = levelmedia:-1, slide
treatIdAsReference = 1
listNum = 0
}
renderObj = COA
renderObj {
10 = IMG_RESOURCE
10.stdWrap.wrap = <img src="|
10.file.import.data = file:current:publicUrl
20 = TEXT
20.stdWrap.wrap = " title="|
20.data = file:current:title
30 = TEXT
30.stdWrap.wrap = " alt="|" />
30.data = file:current:title
}
stdWrap.wrap = |
stdWrap.required = 1
}
}

tt_news category image url

I need the url of the image from tt_news category to fill conf.tt_news.10.stdWrap.ifEmpty. Does anyone have an idea. My approach
lib.catimage = TEXT
lib.catimage {
table = tt_news_cat
select {
pidInList = 2
andWhere {
data = GPVar:tx_ttnews|cat
....????
page.headerData {
15 = RECORDS
15 {
source.data = GPvar:tx_ttnews|tt_news
tables = tt_news
conf.tt_news = COA
conf.tt_news.10 = IMG_RESOURCE
conf.tt_news.10.file {
width = 403
import = uploads/pics/
import.field = image
import.listNum = 0
}
conf.tt_news.10.stdWrap.ifEmpty < lib.catimage
wrap = <link rel="image_src" href="{$BaseUrl}|" />
}
}
I have a new approach, but do not see the error. If I take out the commented brace the path is correct but the syntax of the script is incorrect. The first part also does not work anymore. Here the modified version.
page.headerData {
15 = RECORDS
15 {
source.data = GPvar:tx_ttnews|tt_news
tables = tt_news
conf.tt_news = COA
conf.tt_news.10 = IMG_RESOURCE
conf.tt_news.10.file {
width = 403
import = uploads/pics/
import.field = image
import.listNum = 0
}
conf.tt_news.10.stdWrap.ifEmpty.cObject = CONTENT
conf.tt_news.10.stdWrap.ifEmpty.cObject {
table = tt_news_cat
select {
selectFields = image
pidInList = 2
languageField = sys_language_uid
where = deleted=0 AND hidden=0
andWhere {
data = GPvar:tx_ttnews|category
wrap = uid=|
intval = 1
}
}
#}
renderObj = TEXT
renderObj.field = image
}
wrap = <link rel="image_src" href="{$BaseUrl}|" />
}
}