typo3 - 如何在 tt_content 中为 meta og:image 获取第一张图片
问题描述
如果 tt_content 中有任何图像,我正在尝试获取 tt_content 中要在 Open Graph (og:image) 中使用的第一个现有图像。
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="|">
}
}
}
}
上面的代码只返回后备(logo)。非常适合没有图像的页面和 tt_content,但我希望与 tt_content 中具有图像的页面不同。
解决方案
我简化了一点;希望它不会过于简化,但它应该可以工作:
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="|" >
}
}
}
}
推荐阅读
- swift - UICollectionViewCell 锚/约束男生错误
- reactjs - 覆盖 React TypeScript 默认锚道具
- react-native - 如何在 React Navigation 中使用 NavigationService 重置导航器?
- python - 关于创建具有偶数和赔率分开的随机列表的作业问题
- spring-boot - 如何使用spring boot禁用tomcat清单扫描?
- python - 沿最后一维不同大小的Tensorflow张量操作
- gulp - Gulp 4 任务不并行运行
- java - Mapping between Swagger OpenAPI model and JPA entity
- typescript - DataSnapshot' 已声明,但其值永远不会被读取。ts(6133)
- c++ - Why can an enumeration inside class A (public) be accessed in class B using scope operator and class A name?