【发布时间】:2018-07-25 06:55:33
【问题描述】:
我在 TYPO3 中访问内容对象中的内容时遇到问题:
在 TYPO3 8.7.11 中运行,我有一个带有内容元素“图像”的页面,并且我在里面加载了一个图像。我想得到这样的输出:
<section class="foo" style="background-image:url('fileadmin/foo.png')">
<h2>[image title]</h2>
<p>[image description]</p>
</section>
我得到了带有图像标题和描述的部分,但我无法获得运行背景图像的图像文件名!
我当前的 Typoscript 如下所示: (在托马斯回答后编辑,但仍未运行)
lib.teaser = CONTENT
lib.teaser {
table = tt_content
select.where = colPos = {$teaser_column}
languageField = sys_language_uid
renderObj = COA
renderObj {
# Attempt 1 (regarding the answer of Thomas Löffler)
# this doesn't work and result in an empty URL
#
# 10 {
# references {
# uid.data = uid
# table = tt_content
# fieldName = media
# }
#
# begin = 0
# maxItems = 1
#
# renderObj = IMG_RESOURCE
# renderObj {
# file.import.data = file:current:publicUrl
# }
# stdWrap.wrap = <section class="teaser" style="background-image:url('|');">
# }
# Attempt 2 (regarding the answer of Bernd Wilke πφ)
# this doesn't work and result in an empty URL
10 = FILES
10 {
references {
uid.data = uid
table = tt_content
fieldName = media
}
# a) did you mean that I want to replace
# my renderObj and use a TEXT object instead?
renderObj = TEXT
renderObj {
data = file:current:publicUrl
}
# b) ... or did you mean that I want to provide
# an IMG_RESOURCE and inside of that I want to
# provide a renderObj = TEXT?
#
# renderObj = IMG_RESOURCE
# renderObj {
# listNum = 0
# override.field = media
# renderObj = TEXT
# renderObj.data = file:current:publicUrl
# }
stdWrap.wrap = <section class="teaser" style="background-image:url('|');">
}
20 = TEXT
20.field = header
20.wrap = <h2 class="hide-text">|</h2>
30 = TEXT
30.field = bodytext
30.wrap = <p>|</p>
90 = TEXT
90.value = </section>
}
}
# ...
# edit: added after Thomas answer below
page {
10 = FLUIDTEMPLATE
10 {
format = html
file = {$root}/Templates/{$template}/Layouts/{$main_layout}.html
layoutRootPath = {$root}/Templates/{$template}/Layouts
partialRootPath = {$root}/Templates/{$template}/Partials
variables {
teaser < lib.teaser
# ... some other variables ...
}
# load templates for sections, otherwise Typo3 won't find your sections
file.stdWrap.cObject = CASE
file.stdWrap.cObject {
key.data = levelfield:-1, backend_layout_next_level, slide
key.override.field = backend_layout
default = TEXT
default.value = {$root}/Templates/{$template}/Templates/Main.html
}
}
}
目前生成此 HTML 代码:
<section class="teaser" style="background-image:url('');">
<h2 class="hide-text">Get our latest products:</h2>
<p></p>
</section>
【问题讨论】:
-
我正在使用fluid_styled_content。现在,我更喜欢插入该图像 URL 的快速解决方案。
标签: typo3 typoscript typo3-8.x