TYPO3:如何创建将由子页面继承的标题图像

时间:2016-09-11 12:41:13

标签: typo3 typoscript

我必须为包含以下要求的标题图像设置TypoScript配置:

编辑器应该能够使用“编辑页面 - 属性 - >资源 - >媒体”对话框为页面定义标题图像。如果页面没有标题图像,则应扫描父页面以查找标题图像,并应使用在到达页面树根目录的路径上找到的第一个标题图像。

编辑者还应该能够将内容元素添加到某个“页眉”部分。此内容元素可以是滑块/菜单或图像。如果添加“图像”类型或“带图像的文本”的内容元素,则仅应呈现图像本身而不应呈现其他附加代码。添加到页眉部分的内容元素应具有优先级。因此,如果页面在页面标题部分中包含内容元素并且还在资源 - >媒体字段中具有图像,则来自该页面的媒体字段或页面树中更高级别上的任何其他页面的图像将被忽略,并且将呈现页面标题部分中的内容元素/图像。

后备:如果页面标题部分中没有内容,并且在页面的媒体字段或其根页中的其他页面中找不到图像,则通过TypoScript常量定义的默认图像应该被渲染以防止标题部分留空。

1 个答案:

答案 0 :(得分:3)

此TypoScript使用覆盖,幻灯片和嵌套的COA对象以符合给定要求的方式呈现标题图像:

lib.fallBackHeaderImage = IMAGE
lib.fallBackHeaderImage {
    file {
        import.cObject = TEXT
        import.cObject.value = {$portal.context.headerImage.filename}
        maxW = 1124
        maxH = 342
    }
}

lib.headerImage = IMAGE
lib.headerImage {
    file {
        import {
            data = levelmedia:-1, slide
            listNum = 0
        }
        treatIdAsReference = 1
        maxW = 1124
        maxH = 342
    }
}

lib.headerContent < styles.content.getLeft
lib.headerContent {
    renderObj < tt_content
    renderObj {
        image >
        image = FILES
        image {
            references {
                table = tt_content
                fieldName = image
                uid.data = uid
            }
            renderObj = IMAGE
            renderObj {
                file {
                    import.data = file:current:originalUid // file:current:uid
                    maxW = 1124
                    maxH = 342
                }
            }
        }
        textpic >
        textpic < .image
    }
}

lib.pageHeader = COA
lib.pageHeader {
    // 10 reserved for prepend content
    20 = COA
    20 {
        10 = COA
        10 {
            10 < lib.fallBackHeaderImage
            stdWrap {
                override {
                    required = 1
                    cObject < lib.headerImage
                }
            }
        }
        stdWrap {
            override {
                required = 1
                cObject < lib.headerContent
            }
        }
    }
    // 30 reserved for appended content
}