TYPO3 File Abstraction Layer FILES listNum - typo3

I have a menu and want to access on media files from the page configurations. This works quite well, but it gives all the images of the media files. ListNum it does not work. Do you have an idea or an alternative solution? Important I want to use file:current:description and file:current:title
after.cObject = FILES
after.cObject {
references {
table = pages
fieldName = media
# listNum = 1 not working
}
renderObj = IMAGE
renderObj {
file.import.data = file:current:originalUid
file.width = 250
file.import.listNum = 1
altText.data = file:current:description
}
}

The code of the OP and of maholtz's answer does not work in current TYPO3 versions any more. Here is the correct TypoScript for 6.2 and beyond:
1 = TMENU
1 {
wrap = <ul>|</ul>
NO = 1
NO {
wrapItemAndSub = <li>|</li>
stdWrap.override.cObject = FILES
stdWrap.override.cObject {
references {
table = pages
fieldName = media
}
renderObj = IMAGE
renderObj {
file.import.data = file:current:uid
file.treatIdAsReference = 1
titleText.data = file:current:title // field:nav_title // field:title
altText.data = file:current:alternative // field:nav_title // field:title
}
# start with second image
begin = 1
# show only one image
maxItems = 1
}
}
}
The parameter begin defines which of multiple images should be used (e.g. if you need one image as a headline background for the page and another one as an icon in the menus).
If you increase the maxItems parameter, multiple images will be returned (if multiple images are defined in the resources tab).
If you want to append/prepend the image to the menu text instead of replacing it, you have to change stdWrap.override.cObject to after.cObject or before.cObject in the above code.

after.cObject = FILES
after.cObject {
references {
table = pages
fieldName = media
# listNum = 1 not working
}
renderObj = IMAGE
renderObj {
file.import.data = file:current:originalUid
file.width = 250
file.import.listNum = 1
altText.data = file:current:description
}
# start with first image
begin = 0
# show only two images
maxItems = 2
}
There are two registered filled:
REGISTER:FILES_COUNT
and
REGISTER:FILE_NUM_CURRENT
Implemented in typo3/sysext/frontend/Classes/ContentObject/FilesContentObject.php

Here comes another example with stacked image references. This code can be used with jquerypicture.
lib.headerImg = COA
lib.headerImg.wrap = <picture alt="some alttext">|</picture>
lib.headerImg {
// <source>
10 = FILES
10 {
references {
table = pages
uid.data = tsfe:id
fieldName = media
}
renderObj = IMG_RESOURCE
renderObj {
file.import.data = file:current:uid
file.treatIdAsReference = 1
stdWrap.dataWrap = <source src="|">
# the 2nd pic gets another attribute
stdWrap.dataWrap.override = <source src="|" media="(min-width:600px)">
stdWrap.dataWrap.override.if.value = 1
stdWrap.dataWrap.override.if.equals.data = register:FILE_NUM_CURRENT
# altText.data = file:current:title
}
begin = 0
maxItems = 2
}
// <noscript>
20 < .10
20.begin = 1
20.maxItems = 1
20.renderObj.stdWrap.dataWrap = <noscript><img src="|" alt="{file:current:title}"></noscript>
}

Related

Get meta data of a file in FILES-Object

I'm trying to get file metadata in a FILES-Object:
I have a CONTENT-Object to build Teaser of subpages of a Page. Because Inheritance of Levelmedia did not work for me in the CONTENT-Object I have build a Fallback with ifEmpty. Here is my TS:
lib.subpages = COA
lib.subpages {
10 = CONTENT
10 {
table = pages
select.where = nav_hide != 1 AND doktype IN (1,3,4)
renderObj = COA
renderObj {
stdWrap.wrap = <div class="grid-elem teaser"><div>|</div</div>
stdWrap.wrap.insertData = 1
stdWrap.innerWrap = |
10 = COA
10 {
10 = FILES
10{
references {
field = media
}
begin = 0
maxItems = 1
renderObj = COA
renderObj {
10 = IMAGE
10 {
file.import.data = file:current:publicUrl
file.crop.data = file:current:crop
file.cropVariant = subpages
altText.data = file:current:alternative
titleText.data = file:current:title
}
}
stdWrap.ifEmpty.cObject = COA
stdWrap.ifEmpty.cObject.10 = FILES
stdWrap.ifEmpty.cObject.10 {
references {
data = levelmedia:-1,slide
}
begin = 0
maxItems = 1
renderObj = COA
renderObj {
10 = IMAGE
10 {
file.import.data = file:current:publicUrl
file.crop.data = file:current:crop
file.cropVariant = subpages
altText.data = file:current:alternative
titleText.data = file:current:title
}
}
}
stdWrap.wrap.typolink.parameter.field = uid
stdWrap.wrap = <figure>|</figure>
}
}
20 = COA
20 {
10 = TEXT
10.wrap =<div class="category">|</div>
10.data = levelfield:1, title
20 = TEXT
20.wrap = <h3 class="teaser-title">|</h3>
20.stdWrap.wrap.typolink.parameter.field = uid
30 = TEXT
30.wrap = <p>|</p>
30.field = abstract
30.crop=150 | ... |1
}
20.wrap = <div class="teaser-content">|</div>
}
}
}
The first FILES gets an image from media-field of the page, and if there is no image, in the ifEmpty-Tree I search for an image in the rootline. That solution gives me the images in the page tree as I expected. But only die FILES in ifEmpty, which is referencing to levelmedia also delivers the metadata of the specific file. The FILES which referencing to "media" gives me only the file without any meta data.
Does anyone have a hint for me for what I'm doing wrong?
Solved: Instead of field = media in the references clause of the FILES-Object it has to be fieldName = media
With this modification the crop variant works and I get the title- and alt-texts as well.

TYPO3 Menu Double up

I have this custom menu setup based on the default section menu. When testing on one content element, it looks good... When I add a second content element to the page both get added to each menu item.
Anyone know what's going on here?
tt_content.menu.20.3.1.sectionIndex.useColPos = -1
tt_content.menu.20.101 < tt_content.menu.20.3
tt_content.menu.20.101 {
1.NO {
stdWrap.cObject = CONTENT
stdWrap.cObject {
table = tt_content
select {
pidInList.field = uid
}
renderObj = COA
renderObj {
10 = FILES
10 {
stdWrap.wrap = <div class="menu-img">|</div>
references {
table = tt_content
fieldName = image
}
renderObj = IMAGE
renderObj {
file {
import.data = file:current:uid
treatIdAsReference = 1
width = 100c
height = 100c
}
altText.data = file:current:alternative
titleText.data = file:current:title
stdWrap.typolink.parameter.data = file:current:link
}
maxItems = 1
}
20 = TEXT
20.field = header
30 = TEXT
30.field = rowDescription
}
}
}
}
This is currently outputting:
<ul>
<li><img/>Heading1Desc1<img2/>Heading2Desc2</li>
<li><img/>Heading1Desc1<img2/>Heading2Desc2</li>
<ul>
What it should be:
<ul>
<li><img/>Heading1Desc1</li>
<li><img2/>Heading2Desc2</li>
</ul>
It is about your CONTENT object.
your selection is strange:
select {
pidInList.field = uid
}
you select all tt_content elements which are in the page with the uid of the current content element.
And your rendering is executed for each record found.
Do you really need to select the contentelement with a cObject again? I think in the menu it should be the current context.
add on:
I would try something like this to render the image before the text (which should be available by default):
before just for the image instead of stdWrap with a full query of all CEs and with a COA for all fields.
have a look to the correct fieldname!
1.NO {
before.cObject = FILES
before.cObject {
stdWrap.wrap = <div class="pic">|</div>
references {
table = tt_content
uid.data = uid
// 'image' or 'media' or ... ???
fieldName = image
}
renderObj = IMAGE
renderObj {
stdWrap.wrap = <div class="pic">|</div>
file {
import.data = file:current:uid
treatIdAsReference = 1
width = 150c
height = 150c
}
altText.data = file:current:alternative
titleText.data = file:current:title
#params = class="menu-img"
// don't do a link inside a link =:-O
#stdWrap.typolink.parameter.data = file:current:link
}
maxItems = 1
}
}
I have tried this many different ways and cannot get it working with the image and fields. So instead I have simply patched my original code using by adding: tt_content.menu.20.101.maxItems = 1 and adding a wrap to the renderObj.
I know this is not how it should be done, but it works for now. But if anyone knows the correct way of doing it let me know!

How to set limit & Order in TYPO3 HMENU

In below TYPO3 script code get pages list from others menu item
I want to set order by latest pages with a limit parameter(limit=5)
special directory include submenu entries and display it at home page
[page|uid = 1]
lib.content_6.stdWrap.preCObject = HMENU
lib.content_6.stdWrap.preCObject {
1 = TMENU
wrap = <div class="wpContentElement wpReferenceList"><ul>|</ul></div>
special = directory
special.value = 94,95,97,378,445
includeNotInMenu = 1
special.range = 1|-2
1 {
NO.wrapItemAndSub = <li class="col-xs-12 col-sm-6 col-lg-3 col-xl-3">|</li>
NO.stdWrap.cObject = COA
NO.stdWrap.cObject {
10 = TEXT
10 {
field = title
wrap = <div>|</div>
}
20 = FILES
20 {
references {
table = pages
uid.field = uid
fieldName = tx_mask_referenceimage
}
renderObj = IMAGE
renderObj {
file.import.data = file:current:uid
file.treatIdAsReference = 1
file.height = 850c
file.width = 850c
}
}
}
}
}
[end]
Maximum can be done with maxItems, but there is no option for your own ordering. You might be able to abuse additionalWhere.
A cleaner solution would be to implement an own itemArrayProcFunc.
1 = TMENU
1 {
maxItems = 5
// additionalWhere = ORDER BY tstamp desc
itemArrayProcFunc = user_menuItemArrayProcFunc->process
}

Typoscript menu image size

In my menu I am using a script to retrieve the image loaded in the page's resources.
Now I need to make it so the image is resized/cropped to exactly the right size. Where can I add the width and height to make it work?
NO {
wrapItemAndSub = <li>|</li>
stdWrap.cObject = COA
stdWrap.cObject {
10 = TEXT
10.field = title
10.wrap = <span>|</span>
20 = FILES
20 {
# Get the images related to the current page
references {
table = pages
fieldName = media
}
# Render each image and wrap it as appropriate
renderObj = TEXT
renderObj {
typolink {
parameter.data = file:current:publicUrl
forceAbsoluteUrl = 1
returnLast = url
}
wrap = |,
}
stdWrap {
# Take only the first image if several are defined
listNum = 0
# Use default image if none is available
ifEmpty.cObject = TEXT
ifEmpty.cObject.typolink {
parameter = fileadmin/templates/example/images/placeholder.png
forceAbsoluteUrl = 1
returnLast = url
}
wrap = <div><img src="|" /></div>
}
}
}
}
If you want to resize the image replace the renderObj = TEXT through renderObj = IMG_RESOURCE
Example:
NO {
wrapItemAndSub = <li>|</li>
stdWrap.cObject = COA
stdWrap.cObject {
10 = TEXT
10.field = title
10.wrap = <span>|</span>
20 = FILES
20 {
# Get the images related to the current page
references {
table = pages
fieldName = media
}
# Render each image and wrap it as appropriate
renderObj = IMG_RESOURCE
renderObj {
file.import.data = file:current:uid
file.treatIdAsReference = 1
file.width = 250c
file.height = 250c
wrap = |,
}
stdWrap {
# Take only the first image if several are defined
listNum = 0
# Use default image if none is available
ifEmpty.cObject = TEXT
ifEmpty.cObject.typolink {
parameter = fileadmin/templates/example/images/placeholder.png
forceAbsoluteUrl = 1
returnLast = url
}
wrap = <div><img src="|" /></div>
}
}
}
To render only one image, you shouldn't make first an list of all images. Use the maxItems setting of FILES and remove the listNum from stdWrap.
20 = FILES
20 {
...
maxItems = 1
...
}
I think you need to use GIFBUILDER.
The GIFBUILDER will pass the Image to for example ImageMagick and will help you to cut/scrop/scale the image to your needs.
Something like
lib.image = IMAGE
lib.image {
file = GIFBUILDER
file {
#use the c in XY to crop
XY = 1024c,768c
format = jpg
10 = IMAGE
10.file = fileadmin/image.jpg
}
}
You can read more about Gifbuilder here:
https://docs.typo3.org/typo3cms/TyposcriptReference/Gifbuilder/Index.html

Typo3 resources media files/sys_file_reference for TMENU

How can I use resources media files -> Description (Caption) for altTag/altText in menu.
In TYPO3 you have the possibility to use the page properties for a resource image and to set additional metadata. I found this reference: data [sys_file_reference] [6] [description]
NO = 1
NO {
ATagTitle.field = title
wrapItemAndSub = |</li>
allWrap = <li>|
after.cObject = IMAGE
after.cObject {
file.import.field = media
file.import = uploads/media/
file.import.listNum = 0
file.width = 250c
altText = {???:description}
altText.insertData = 1
}
stdWrap.htmlSpecialChars = 1
}
Since TYPO3 6.0 the media field uses File Abstraction Layer (FAL) to create references to uploaded objects (e.g. images). Because of this change, you can't use the IMAGE content object to fetch the inserted object, but first have to use the FILES content object.
For you case, the TypoScript should look like this:
after.cObject = FILES
after.cObject {
references.data = levelmedia:-1, slide
references.listNum = 0
renderObj = IMAGE
renderObj.altText.data = file:current:description
renderObj.file {
import.data = file:current:publicUrl
width = 250c
}
}
References: http://docs.typo3.org/typo3cms/TyposcriptReference/ContentObjects/Files/Index.html