typo3 - TypoScript:没有 IMG_RESOURCE 时更改标题字段的换行
问题描述
我有一个带有背景图像和标题的超大屏幕。背景图像来自站点属性,来自特定后端布局列的标题。
当前状态
jumbotron 与背景图像和标题完美配合。但是现在我想根据图像是否在站点属性中来更改标题的 css 类。
结果应该如何(伪代码)
if there is an image:
<div class="jumbotron" style="background-image: url(...)
<h1 class="header-type1">My header with standard styling</h1>
</div>
else:
<h1 class="header-type2">My header with different styling</h1>
这是我的打字稿代码
lib.jumbo < lib.dynamicContent
lib.jumbo {
20.renderObj = COA
20.renderObj {
5 = IMG_RESOURCE
5 {
file {
import = uploads/media/
import.data = levelmedia:-1
treatIdAsReference = 1
import.listNum = 0
width = 1022
height = 472
}
stdWrap {
wrap = <div class="jumbotron" style="background-image: url(|);">
required = 1
}
}
10 = TEXT
10 {
stdWrap {
field = header
required = 1
# if there is one image in the site properties use this wrap
wrap = <h1 class="header-type1">|</h1>
# if there is no image:
wrap < h1 class="header-type2">|</h1>
}
}
# this one should only be displayed too, if there is an image
90 = TEXT
90.value = </div>
}
}
lib.DynamicContent
来自引导包
解决方案
在这里,我们有一个打字稿解决方案会有点复杂的案例。但与此同时,我们还有其他选择:
为什么不使用 FLUID 进行渲染?
lib.jumbo < lib.dynamicContent
lib.jumbo {
20.renderObj = FLUIDTEMPLATE
20.renderObj {
template = Header
templateRootPaths.0 = EXT:my_site_ext/Resources/Private/page/Templates
variables {
header = TEXT
header.field = header
jumboImage = IMG_RESOURCE
jumboImage {
file {
import = uploads/media/
import.data = levelmedia:-1
treatIdAsReference = 1
import.listNum = 0
width = 1022
height = 472
}
}
}
}
在引用的流体模板文件中:
<f:if condition="{jumboImage}">
<f:then>
<div class="jumbotron" style="background-image: url({jumboImage})">
<h1 class="header-type1">{header->f:format.raw()}</h1>
</div>
</f:if>
<f:else>
<h1 class="header-type2">{header->f:format.raw()}</h1>
</f:else>
</f:if>
注意:
图像生成可以优化
我假设你甚至根本不需要这个打字稿,因为你可能会使用lib.jumbo
类似的<f:cObject typoscriptObjectPath="lib.jumbo" arguments="..." />
在那个地方,您可以使用部分或仅部分来调用{f:uri.image image="..."}
viewhelper。
推荐阅读
- swift - 为什么函数调用需要参数名称,而分配给变量的函数却不允许?
- java - 如何在 Java 中使用 HTTP/REST 交换访问令牌(Oauth 2.0)的授权码?
- python - 如果前一列中的值不同,则计数器会增加,但在其他列值更改时会重置?
- mysql - 从 MySQL 视图中选择
- javascript - 可查看的内容会在设定的时间间隔内发生变化 - 但之前的内容会在之后闪现
- r - 将“绘制”标签保持在 ggplot2 的范围内
- python - 网页开发模板
- r - 使用循环 1 测试素数:sqrt(x)
- excel - Worksheet_Change 在虚拟化 Win Server SP2 上不起作用
- input - 是否也有类似 HTML5 的输入控件?