我有一个菜单,想要从页面配置访问媒体文件。这很好用,但它提供了媒体文件的所有图像。 ListNum它不起作用。您有想法或替代解决方案吗?重要我想使用file:current:description和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
}
}
答案 0 :(得分:3)
OP的代码和maholtz的答案不再适用于当前的TYPO3版本。这是适用于6.2及更高版本的正确TypoScript:
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
}
}
}
参数begin
定义应使用多个图像中的哪一个(例如,如果您需要一个图像作为页面的标题背景,另一个图像作为菜单中的图标)。
如果增加maxItems
参数,将返回多个图像(如果在资源选项卡中定义了多个图像)。
如果您想将图片追加/添加到菜单文字而不是替换它,则必须在上面的代码中将stdWrap.override.cObject
更改为after.cObject
或before.cObject
。
答案 1 :(得分:0)
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
}
有两个注册填充:
REGISTER:FILES_COUNT
和
REGISTER:FILE_NUM_CURRENT
在typo3 / sysext / frontend / Classes / ContentObject / FilesContentObject.php中实现
答案 2 :(得分:0)
这是堆叠图像参考的另一个例子。此代码可与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>
}