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

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

Related

TypoScript condition to check if specific list_type is on a page

I try to have a condition in TypoScript to find out if a certain list_type is on the page (plugin). In the docs I can't find anything about that. Is it even possible at all?
lib.hasNewsOnPage = TEXT
lib.hasNewsOnPage {
value = 1
if.isTrue.numRows {
table = tt_content
select.where.dataWrap = pid = {TSFE:id} AND colPos = 1 AND list_type = 'news_pi1'
}
}
Try this:
Return 1 if the plugin News is fund on the current page (colpos 1)
lib.hasNewsOnPage = TEXT
lib.hasNewsOnPage {
value = 0
stdWrap {
override {
cObject = CONTENT
cObject {
table = tt_content
select {
where = colPos=1 AND list_type = 'news_pi1'
max = 1
}
renderObj = TEXT
renderObj {
value = 1
}
}
}
}
}

get altText in renderObject in typoscript

i have the following typoscript which works as expected:
table = tx_news_domain_model_news
select {
selectFields = tx_news_domain_model_news.*, rand()
pidInList = 111
max = 1
orderBy = rand()
languageField = sys_language_uid
}
renderObj = COA
renderObj {
10 = FILES
10 {
references {
table = tx_news_domain_model_news
uid.data = uid
fieldName = fal_media
}
renderObj = IMAGE
renderObj {
wrap = <div class="news-list-item__image">|</div>
file.import.data = file:current:originalUid
file.width = 600c
file.height = 345c
}
}
....
but i need an alt attribute for the image too and don`t know how to achieve this:
renderObj {
wrap = <div class="news-list-item__image">|</div>
file.import.data = file:current:originalUid
file.width = 600c
file.height = 345c
altText = ?????
}
Is there a possibility to get the alt attribute here?
Thanks!
This should work:
renderObj {
// your code
titleText.data = file:current:title
altText.data = file:current:alternative
}

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

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

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?

TYPO3 6.0: Render images of current page from border column in FAL

I've have the following snippets and I don't get it to work.
COL3 = FILES
COL3 {
references {
table = tt_content
uid = 14
fieldName = image
}
renderObj = TEXT
renderObj {
data = file:current:publicUrl
wrap = <img src="|">
}
}
Snippet works so far, but I want to use it with current page & colPos = 3. So something like:
table = tt_content
select {
where = colPos = 3
orderBy = sorting
languageField = sys_language_uid
}
It feels like I've tried almost everything.
I really appreciate every help I can get...
Thank's alot!!
That's sounds better to me :
COL3 = CONTENT
COL3 {
table = tt_content
select {
where = colPos = 3
}
renderObj = FILES
renderObj {
references {
table = tt_content
fieldName = image
}
renderObj = IMAGE
renderObj {
file.import.data = file:current:publicUrl
}
}
}
I presume the select attribute does not work with references.
Try this solution (not tested) to use with any content element.
...
references {
table = tt_content
uid.data = uid
fieldName = image
}
Another idea:
COL3 = CONTENT
COL3 {
table = tt_content
select {
where = colPos = 3
}
renderObj = FILES
renderObj {
references {
table = tt_content
fieldName = image
}
renderObj = TEXT
renderObj {
data = file:current:publicUrl
wrap = <img src="|">
}
}
}