How to get media content in typoscript assigned to the current page? - typo3

I have 3 pics that are assigned to my page and I am trying to put them into a variable in typoscript.
Here is my code:
temp.pics = FILES
temp.pics {
references {
table = pages
uid.data = page:uid
fieldName = media
}
renderObj = IMAGE
renderObj {
file.import.data = file:current:originalUid
altText.data = file:current:title
wrap = <li>|</li>
}
stdWrap.wrap = <ul id="Gallery" class="gallery">|</ul>
}
page.10 {
variables {
pics < temp.pics
}
}
And in my HTML layout I only get:
<ul id="Gallery" class="gallery"></ul>
Does anybody have an idea why it is empty?

Related

Get an image from a UID using typoscriptObjectPath in a Fluid template?

In my Fluid template I have a uid of a category.
How can I get an image from a field on that category?
I've tried <f:cObject typoscriptObjectPath="lib.catImage" data="{myuid}" />
Then something like:
lib.catImage = CONTENT
lib.catImage {
table = sys_category
current = 1
select {
fieldName = cat_image
}
renderObj {
???
}
}
You don't want to get CONTENT but FILES:
lib.catImage = FILES
lib.catImage {
maxItems = 1
references {
table = sys_category
uid.data = field:uid
fieldName = images
}
renderObj = TEXT
renderObj {
stdWrap.data = file:current:uid
}
}
And call it via <f:cObject typoscriptObjectPath="lib.catImage" data="{uid: {myuid}}" />

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="|">
}
}

Typolink content in menu?

I am trying to make a menu that displays the page's first content element header and image and have them be links. But the typolink part doesn't seem to work for me:
lib.menu = HMENU
lib.menu {
1 = TMENU
1.NO {
doNotLinkIt = 1
wrapItemAndSub = <div>|</div>
stdWrap.cObject = CONTENT
stdWrap.cObject {
table = tt_content
select {
pidInList.field = uid
}
renderObj = COA
renderObj {
10 = TEXT
10.field = header
10.typolink.parameter.field = uid
}
}
}
}
Just to add give the full working example. Using section.field = uid you can link to the content element itself.
lib.menu = HMENU
lib.menu {
1 = TMENU
1.NO {
doNotLinkIt = 1
wrapItemAndSub = <div>|</div>
stdWrap.cObject = CONTENT
stdWrap.cObject {
table = tt_content
select {
pidInList.field = uid
}
renderObj = COA
renderObj {
10 = TEXT
10.field = header
10.typolink {
parameter.field = pid
section.field = uid
}
}
}
}
}

TYPO3 6.2: Image-Slider with Hyperlink from Page Ressources

I did a well working Imageslider from the page ressources. Now I'm trying to hyperlink those Images with a Link also provided in the ressource. This is what I have so far:
TS:
lib.headerimage = COA_INT
lib.headerimage {
1 = COA
1 {
stdWrap.required = 1
stdWrap.outerWrap.cObject = TEXT
stdWrap.outerWrap.cObject.value = <li><img src=" | " /></li>
2 = IMG_RESOURCE
2 {
file {
import.data = levelmedia:-1, slide
import.listNum = 0
treatIdAsReference = 1
}
}
}
2 < .1
2.2.file.import.listNum = 1
3 < .1
3.2.file.import.listNum = 2
}
Layout:
<div class="headerimage">
<ul>
<f:render section="headerimage" />
</ul>
</div>
This Results in the expected HTML Output
<ul>
<li>
<img />
</li>
</ul>
But I want the following Output
<ul>
<li>
<a href="link_from_page_ressource">
<img />
</a>
</li>
</ul>
How do I get those Links around my Images?
Thanks in advance
UPDATE
Solution:
lib.headerimage = COA
lib.headerimage {
1 = FILES
1 {
references {
data = levelmedia:-1, slide
}
renderObj = COA
renderObj {
wrap = <li>|</li>
1 = IMAGE
1 {
file.import.data = file:current:publicUrl
altText.data = file:current:title
stdWrap.typolink.parameter.data = file:current:link
}
}
}
}
You shoul use FILES to handle this. Use something like (not tested!)
lib.headerimage = COA
lib.headerimage {
wrap = <ul>|</ul>
10 = FILES
10 {
references {
data = levelmedia:-1, slide
}
renderObj = COA
renderObj {
10 = IMAGE
10 {
file.import.data = file:current:publicUrl
altText.data = file:current:title
stdWrap.typolink.parameter.data = file:current:link
wrap = <li>|</li>
}
}
}
}
Can you try this?
lib.headerimage = COA
lib.headerimage {
wrap = <ul>|</ul>
1 = IMAGE
1 {
file {
import.data = levelmedia:-1, slide
import.listNum = 0
treatIdAsReference = 1
}
stdWrap.typolink.parameter.data = file:current:link
stdWrap.outerWrap = <ul>|</ul>
}
2 < .1
2.file.import.listNum = 1
3 < .1
3.file.import.listNum = 2
}
lib.randomImage = COA_INT
lib.randomImage.10 = FILES
lib.randomImage.10.sorting = rand()
lib.randomImage.10 {
references {
table = pages
data = levelmedia:-1, slide
treatIdAsReference = 1
}
maxItems= 1
renderObj = COA
renderObj {
10 = IMAGE
10 {
file {
import {
data = file:current:publicUrl
}
}
}
}
stdWrap {
wrap = |
}
}
Reference link: http://www.t3hut.com/blog/post/news/detail/News/random-image-from-page-resources-files-in-typo3-62.html
This ts works for me !

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
}
}