我的问题似乎微不足道,如果是的话,对不起!我目前正在学习typo3和typoscript。我想创建一个带有动态背景图像的模板。该图像存储在目录中。我想从表tt_content中获取图像名称。然而,这种作品的方式让我感到困惑,我不知道我对它的看法是否合适。
代码如下所示:
20 = CONTENT
20.table = tt_content
20.select{
where = pid = 79
}
20.headerImagePath = COA
20.headerImagePath {
10 = TEXT
10.stdWrap.field = image
10.stdWrap.wrap = <div class="background-media" style="background-image: url('|'); background-repeat: no-repeat; background-size: cover; background-attachment: fixed; background-position: 50%;" data-start="background-position:50% 50%"
data-70-top-bottom="background-position:50% 70%">
</div>
}
我希望将有关图像的信息(代码中的div部分)存储在变量中并将其放入我的模板中。我的代码的模板部分如下所示:
<f:format.raw>{headerimage}</f:format.raw>
或
<f:cObject typoscriptObjectPath="headerimage" />
所以我的问题是,我是从数据库中选择东西并存储到变量中的方式是正确的,我在模板中调用它们的方式是正确的吗?如果上面的方法可行,但我有一些小错误,这是好的做法还是我应该采取不同的做法?
亲切的问候
阿迪
答案 0 :(得分:1)
您的代码段不起作用,因为您的结构非常错误。
开启
20.headerImagePath = COA
您尝试在CONTENT OBJECT ARRAY上创建新的CONTENT OBJECT。
20 = CONTENT
这不起作用。
但CONTENT对象有一个名为renderObj的属性。
请看以下示例:
试试这样:
lib.headerImagePath = CONTENT
lib.headerImagePath {
# first call the content you need
table = tt_content
select {
# Add your colPos
# In this example i store my header image in colpos 9
where = colPos = 9
# PID from current field or define your own
# pidInList = 123
pidInList.field = uid
languageField = sys_language_uid
}
renderObj = COA
renderObj {
# FILES object was introduced in TYPO3 6.x
10 = FILES
10 {
# Set a reference to let the file object know, where we will get the images
references {
table = tt_content
uid.field = uid
fieldName = image
}
# make sure we only get the first image in set
maxItems = 1
renderObj = COA
renderObj {
# We only need the url and not the complete image. So we need a IMG_RESOURCE and not an IMAGE Object
10 = IMG_RESOURCE
10 {
stdWrap {
wrap = <div class="background-media" style="background-image: url('|'); background-repeat: no-repeat; background-size: cover; background-attachment: fixed; background-position: 50%;" data-start="background-position:50% 50%" data-70-top-bottom="background-position:50% 70%"></div>
required = 1
}
# Import file from current object
# and treat the id as a reference (TYPO3 File Abstraction Layer)
file {
import.data = file:current:uid
treatIdAsReference = 1
}
}
}
}
}
}
这里他们直接从页面属性中的MEDIA元素获取标题图像:
答案 1 :(得分:0)
获取标题图像为背景我们,它也在使用拼写错误的多语言工作6.x
page.cssInline {
10 = FILES
10 {
references.data = levelmedia:-1, slide
references.listNum = 0
renderObj = TEXT
renderObj.data = file:current:publicUrl
renderObj.wrap (
.title-1 {
background-image: url(../|) !important;
}
)
}
}
感谢http://www.derhansen.de/2013/02/using-fal-media-in-typo3-60-for-inline.html