Typo3 v9.5LTS 部分不渲染
Typo3 v9.5LTS partial not rendering
试图了解在 typo3 中进行模板化的正确方法,我从 typo3 6.2 到 typo3 v9.5,一切都是新的。我已经实现了使用 DCE,创建后端布局,现在我正在尝试创建一个重复元素以在具有不同模板的多个页面上使用。
与带有 typo3 提供的主模板的全新 typo3 安装相比,我可以看到他们使用 file inside
:
ext/your_template/Resources/Private/Partials/Page/Structure/Footercontent
然后在模板中,他们呈现 html 文件,该文件从主模板(我猜)加载元素。
Here you can see the render
当我尝试在我自己的页面中复制它时,我的问题就来了。它不在我的页面中呈现,甚至 html 基本结构也不呈现。
FooterContent.html里面as I show in this picture
以及我主模板中的渲染调用 like in this picture
Home.html(模板)
<f:section name="Footer">
<f:render partial="Structure/FooterContent" arguments="{_all}" />
</f:section>
FooterContent.html
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<section class="section footer-section footer-section-content">
<div class="beez_footer">
<div class="beez_footer_top beez_section">
<div class="beez_ft_left">
<f:cObject typoscriptObjectPath="lib.dynamicContent" data="{colPos: '5'}" />
</div>
<div class="beez_ft_right">
<f:cObject typoscriptObjectPath="lib.dynamicContent" data="{colPos: '6'}" />
</div>
</div>
<div class="beez_footer_middle beez_section">
<div class="beez_ft_left">
<f:cObject typoscriptObjectPath="lib.dynamicContent" data="{colPos: '7'}" />
</div>
<div class="beez_ft_middle">
<f:cObject typoscriptObjectPath="lib.dynamicContent" data="{colPos: '8'}" />
</div>
<div class="beez_ft_right">
<f:cObject typoscriptObjectPath="lib.dynamicContent" data="{colPos: '9'}" />
</div>
</div>
<div class="beez_footer_bottom beez_section">
<div class="beez_ft_left">
<f:cObject typoscriptObjectPath="lib.dynamicContent" data="{colPos: '10'}" />
</div>
<div class="beez_ft_right">
<f:cObject typoscriptObjectPath="lib.dynamicContent" data="{colPos: 11}" />
</div>
</div>
</div>
</section>
</html>
setup.typoscript 在 (ext/your_template/Configuration/Typoscript/):
######################
#### DEPENDENCIES ####
######################
<INCLUDE_TYPOSCRIPT: source="FILE:EXT:fluid_styled_content/Configuration/TypoScript/setup.typoscript">
################
#### HELPER ####
################
<INCLUDE_TYPOSCRIPT: source="FILE:EXT:nubis_theme/Configuration/TypoScript/Helper/DynamicContent.typoscript">
##############
#### PAGE ####
##############
page = PAGE
page {
typeNum = 0
shortcutIcon = EXT:nubis_theme/Resources/Public/Icons/favicon.ico
10 = FLUIDTEMPLATE
10 {
# Template names will be generated automaticly by converting the applied
# backend_layout, there is no explicit mapping nessesary anymore.
#
# BackendLayout Key
# subnavigation_right_2_columns -> SubnavigationRight2Columns.html
#
# Backend Record
# uid: 1 -> 1.html
#
# Database Entry
# value: -1 -> None.html
# value: pagets__subnavigation_right_2_columns -> SubnavigationRight2Columns.html
templateName = TEXT
templateName {
cObject = TEXT
cObject {
data = pagelayout
required = 1
case = uppercamelcase
split {
token = pagets__
cObjNum = 1
1.current = 1
}
}
ifEmpty = Default
}
templateRootPaths {
0 = EXT:nubis_theme/Resources/Private/Templates/Page/
1 = {$page.fluidtemplate.templateRootPath}
}
partialRootPaths {
0 = EXT:nubis_theme/Resources/Private/Partials/Page/
1 = {$page.fluidtemplate.partialRootPath}
}
layoutRootPaths {
0 = EXT:nubis_theme/Resources/Private/Layouts/Page/
1 = {$page.fluidtemplate.layoutRootPath}
}
dataProcessing {
10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
10 {
references.fieldName = media
}
20 = TYPO3\CMS\Frontend\DataProcessing\MenuProcessor
20 {
levels = 2
includeSpacer = 1
as = mainnavigation
}
}
}
meta {
viewport = {$page.meta.viewport}
robots = {$page.meta.robots}
apple-mobile-web-app-capable = {$page.meta.apple-mobile-web-app-capable}
description = {$page.meta.description}
description {
override.field = description
}
author = {$page.meta.author}
author {
override.field = author
}
keywords = {$page.meta.keywords}
keywords {
override.field = keywords
}
X-UA-Compatible = {$page.meta.compatible}
X-UA-Compatible {
attribute = http-equiv
}
# OpenGraph Tags
og:title {
attribute = property
field = title
}
og:site_name {
attribute = property
data = TSFE:tmpl|setup|sitetitle
}
og:description = {$page.meta.description}
og:description {
attribute = property
field = description
}
og:image {
attribute = property
stdWrap.cObject = FILES
stdWrap.cObject {
references {
data = levelfield:-1, media, slide
}
maxItems = 1
renderObj = COA
renderObj {
10 = IMG_RESOURCE
10 {
file {
import.data = file:current:uid
treatIdAsReference = 1
width = 1280c
height = 720c
}
stdWrap {
typolink {
parameter.data = TSFE:lastImgResourceInfo|3
returnLast = url
forceAbsoluteUrl = 1
}
}
}
}
}
}
}
includeCSSLibs {
}
includeCSS {
nubis_theme_layout = EXT:nubis_theme/Resources/Public/Css/layout.min.css
}
includeJSLibs {
}
includeJS {
}
includeJSFooterlibs {
}
includeJSFooter {
nubis_theme_scripts = EXT:nubis_theme/Resources/Public/JavaScript/Dist/scripts.js
}
}
################
#### CONFIG ####
################
config {
absRefPrefix = auto
contentObjectExceptionHandler = 0
no_cache = {$config.no_cache}
uniqueLinkVars = 1
pageTitleFirst = 1
linkVars = L
prefixLocalAnchors = {$config.prefixLocalAnchors}
renderCharset = utf-8
metaCharset = utf-8
doctype = html5
removeDefaultJS = {$config.removeDefaultJS}
inlineStyle2TempFile = 1
admPanel = {$config.admPanel}
debug = 0
cache_period = 86400
sendCacheHeaders = {$config.sendCacheHeaders}
intTarget =
extTarget =
disablePrefixComment = 1
index_enable = 1
index_externals = 1
index_metatags = 1
headerComment = {$config.headerComment}
// Disable Image Upscaling
noScaleUp = 1
// Compression and Concatenation of CSS and JS Files
compressJs = 0
compressCss = 0
concatenateJs = 0
concatenateCss = 0
}
然后,在我的网站中,我只获得了我能够从模板中显示的内容。
换句话说,除了渲染部分之外的所有内容。
我看不到与此相关的任何问题,typo3 的文档也没有对此进行澄清。
我一定是错过了什么,但我不知道是什么。
编辑:添加setup.typoscript(我使用的是安装主题包时提供的默认设置:https://sitepackagebuilder.com)
根据评论,解决方案应该是将该部分添加到默认页面布局文件。
默认情况下(来自 sitepackagebuilder)使用布局文件,因此模板中定义的部分必须在布局文件中定义。
在默认布局文件中,您发现只有 "main" 部分被渲染。
要添加 Footer
部分,请在布局中的某处放置一个 RenderViewHelper
:
<f:render section="Footer" />
如果你想让它成为可选的,你可以将属性 optional="true"
添加到 ViewHelper,这样你就不必在不需要的每个模板中定义页脚部分。
FLUIDTEMPLATE 的结构如下所示:
Templates
可以包含 Partials
并且可以有 Sections
Partials
可以包含其他 Partials
Layouts
包含 Templates
可以渲染 Sections
也可以包含 Partials
如果您想为您的全局页面呈现页脚,请将页脚 Partial
放入您的 Layout
文件中。如果您想要一个取决于所使用模板的页脚,请将页脚放在模板的 Section
中,然后在 Layout
.
中渲染 Section
只是为了澄清 René 的回答:
流体模板:
templates - 这是流体的入口。如果调用流体,则调用模板 (<f:layout name="layoutname" />
)。模板可以决定布局;如果这样做,渲染从布局开始
layouts - 它们旨在提供一般结构。这可以通过从确定模板和/或部分中插入不同的部分来实现。
partials - 这些是您的页面将要构建的灵活构建块。每当你有一个可能更频繁出现的数据块,或者它本身就是一个单元时,从中提取一部分,这样你就可以重用它并构建你的流体。
部分 可以作为子块出现在模板和部分中。
如果您插入像 <f:render section="sectionname" />
这样的部分,该部分应该在当前文件中 - 除了布局,他们希望它们的部分在模板中。
如果您想从另一个文件中插入一个部分,您只能从部分文件中插入部分:<f:render section="sectionname" partial="partialname" />
。
如果省略部分名称,则插入整个部分 (<f:render partial="partialname" />
)
一般来说,所有带有 f:render
的插入都不会传输任何数据(流体变量),除了:布局获取确定模板已知的所有数据,并且模板中从布局插入的部分知道所有数据初始模板的数据。
对于所有其他插入,您可能需要使用 f:render
viewhelper 的 arguments
参数传输数据:
<f:render section="sectionname" arguments="{ind1:'data1', ind2:'data2'}" />
特殊情况:您可以使用 arguments="{_all}"
传输所有(本地已知的)数据
感谢 René Pflamm 和 Bernd Wilke 的解释。由于我来自 tpyo3 v6.2,我在那里使用标记记录在多个模板上重复相同的项目:
LOGO = RECORDS
LOGO.tables = tt_content
LOGO.source = 1
然后在模板中
<div class="myClass">###LOGO###</div>
这使我能够从 typo3 中的文件夹中获取一些与其 ID 匹配的元素。
我不知道这是否还能用,但我创建了一个简单的函数
(located at
ext/your_theme/Configuration/Typoscript/Helper/DynamicContent.typoscript)
在我调用 typoscriptObjectPath="lib.dynamicContentFunction"
的部分中使用,这允许我通过数据参数调用我想要呈现的元素的 id。这是一个示例和函数:
<f:cObject typoscriptObjectPath="lib.dynamicContentFunction" data="{Uid: '11'}" />
和
lib.dynamicContentFunction = COA
lib.dynamicContentFunction {
5 = LOAD_REGISTER
5 {
Uid.cObject = TEXT
Uid.cObject {
field = Uid
}
}
20 = CONTENT
20 {
table = tt_content
select {
includeRecordsWithoutDefaultTranslation = 1
orderBy = sorting
where = {#uid}={register:Uid}
where.insertData = 1
pidInList = -1
recursive = 99
}
stdWrap {
dataWrap = {register:wrap}
required = 1
}
}
90 = RESTORE_REGISTER
}
警告:如果您有很多元素,这可能会影响您的网站速度。
另外,我想知道你们是怎么想的。有一个更好的方法吗?
目的:呈现在 typo3 中创建的确定内容元素,并可从那里编辑,我可以通过 selecting 其 id 调用部分内容。如果可能,该函数必须通过数据参数从确定的错字 page/folder(id) 和 select 中搜索所需的内容元素。所以这样我就可以使用一个可编辑的页脚元素,例如在每个页面上重复。
试图了解在 typo3 中进行模板化的正确方法,我从 typo3 6.2 到 typo3 v9.5,一切都是新的。我已经实现了使用 DCE,创建后端布局,现在我正在尝试创建一个重复元素以在具有不同模板的多个页面上使用。
与带有 typo3 提供的主模板的全新 typo3 安装相比,我可以看到他们使用 file inside :
ext/your_template/Resources/Private/Partials/Page/Structure/Footercontent
然后在模板中,他们呈现 html 文件,该文件从主模板(我猜)加载元素。
Here you can see the render
当我尝试在我自己的页面中复制它时,我的问题就来了。它不在我的页面中呈现,甚至 html 基本结构也不呈现。
FooterContent.html里面as I show in this picture 以及我主模板中的渲染调用 like in this picture
Home.html(模板)
<f:section name="Footer">
<f:render partial="Structure/FooterContent" arguments="{_all}" />
</f:section>
FooterContent.html
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<section class="section footer-section footer-section-content">
<div class="beez_footer">
<div class="beez_footer_top beez_section">
<div class="beez_ft_left">
<f:cObject typoscriptObjectPath="lib.dynamicContent" data="{colPos: '5'}" />
</div>
<div class="beez_ft_right">
<f:cObject typoscriptObjectPath="lib.dynamicContent" data="{colPos: '6'}" />
</div>
</div>
<div class="beez_footer_middle beez_section">
<div class="beez_ft_left">
<f:cObject typoscriptObjectPath="lib.dynamicContent" data="{colPos: '7'}" />
</div>
<div class="beez_ft_middle">
<f:cObject typoscriptObjectPath="lib.dynamicContent" data="{colPos: '8'}" />
</div>
<div class="beez_ft_right">
<f:cObject typoscriptObjectPath="lib.dynamicContent" data="{colPos: '9'}" />
</div>
</div>
<div class="beez_footer_bottom beez_section">
<div class="beez_ft_left">
<f:cObject typoscriptObjectPath="lib.dynamicContent" data="{colPos: '10'}" />
</div>
<div class="beez_ft_right">
<f:cObject typoscriptObjectPath="lib.dynamicContent" data="{colPos: 11}" />
</div>
</div>
</div>
</section>
</html>
setup.typoscript 在 (ext/your_template/Configuration/Typoscript/):
######################
#### DEPENDENCIES ####
######################
<INCLUDE_TYPOSCRIPT: source="FILE:EXT:fluid_styled_content/Configuration/TypoScript/setup.typoscript">
################
#### HELPER ####
################
<INCLUDE_TYPOSCRIPT: source="FILE:EXT:nubis_theme/Configuration/TypoScript/Helper/DynamicContent.typoscript">
##############
#### PAGE ####
##############
page = PAGE
page {
typeNum = 0
shortcutIcon = EXT:nubis_theme/Resources/Public/Icons/favicon.ico
10 = FLUIDTEMPLATE
10 {
# Template names will be generated automaticly by converting the applied
# backend_layout, there is no explicit mapping nessesary anymore.
#
# BackendLayout Key
# subnavigation_right_2_columns -> SubnavigationRight2Columns.html
#
# Backend Record
# uid: 1 -> 1.html
#
# Database Entry
# value: -1 -> None.html
# value: pagets__subnavigation_right_2_columns -> SubnavigationRight2Columns.html
templateName = TEXT
templateName {
cObject = TEXT
cObject {
data = pagelayout
required = 1
case = uppercamelcase
split {
token = pagets__
cObjNum = 1
1.current = 1
}
}
ifEmpty = Default
}
templateRootPaths {
0 = EXT:nubis_theme/Resources/Private/Templates/Page/
1 = {$page.fluidtemplate.templateRootPath}
}
partialRootPaths {
0 = EXT:nubis_theme/Resources/Private/Partials/Page/
1 = {$page.fluidtemplate.partialRootPath}
}
layoutRootPaths {
0 = EXT:nubis_theme/Resources/Private/Layouts/Page/
1 = {$page.fluidtemplate.layoutRootPath}
}
dataProcessing {
10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
10 {
references.fieldName = media
}
20 = TYPO3\CMS\Frontend\DataProcessing\MenuProcessor
20 {
levels = 2
includeSpacer = 1
as = mainnavigation
}
}
}
meta {
viewport = {$page.meta.viewport}
robots = {$page.meta.robots}
apple-mobile-web-app-capable = {$page.meta.apple-mobile-web-app-capable}
description = {$page.meta.description}
description {
override.field = description
}
author = {$page.meta.author}
author {
override.field = author
}
keywords = {$page.meta.keywords}
keywords {
override.field = keywords
}
X-UA-Compatible = {$page.meta.compatible}
X-UA-Compatible {
attribute = http-equiv
}
# OpenGraph Tags
og:title {
attribute = property
field = title
}
og:site_name {
attribute = property
data = TSFE:tmpl|setup|sitetitle
}
og:description = {$page.meta.description}
og:description {
attribute = property
field = description
}
og:image {
attribute = property
stdWrap.cObject = FILES
stdWrap.cObject {
references {
data = levelfield:-1, media, slide
}
maxItems = 1
renderObj = COA
renderObj {
10 = IMG_RESOURCE
10 {
file {
import.data = file:current:uid
treatIdAsReference = 1
width = 1280c
height = 720c
}
stdWrap {
typolink {
parameter.data = TSFE:lastImgResourceInfo|3
returnLast = url
forceAbsoluteUrl = 1
}
}
}
}
}
}
}
includeCSSLibs {
}
includeCSS {
nubis_theme_layout = EXT:nubis_theme/Resources/Public/Css/layout.min.css
}
includeJSLibs {
}
includeJS {
}
includeJSFooterlibs {
}
includeJSFooter {
nubis_theme_scripts = EXT:nubis_theme/Resources/Public/JavaScript/Dist/scripts.js
}
}
################
#### CONFIG ####
################
config {
absRefPrefix = auto
contentObjectExceptionHandler = 0
no_cache = {$config.no_cache}
uniqueLinkVars = 1
pageTitleFirst = 1
linkVars = L
prefixLocalAnchors = {$config.prefixLocalAnchors}
renderCharset = utf-8
metaCharset = utf-8
doctype = html5
removeDefaultJS = {$config.removeDefaultJS}
inlineStyle2TempFile = 1
admPanel = {$config.admPanel}
debug = 0
cache_period = 86400
sendCacheHeaders = {$config.sendCacheHeaders}
intTarget =
extTarget =
disablePrefixComment = 1
index_enable = 1
index_externals = 1
index_metatags = 1
headerComment = {$config.headerComment}
// Disable Image Upscaling
noScaleUp = 1
// Compression and Concatenation of CSS and JS Files
compressJs = 0
compressCss = 0
concatenateJs = 0
concatenateCss = 0
}
然后,在我的网站中,我只获得了我能够从模板中显示的内容。 换句话说,除了渲染部分之外的所有内容。 我看不到与此相关的任何问题,typo3 的文档也没有对此进行澄清。 我一定是错过了什么,但我不知道是什么。
编辑:添加setup.typoscript(我使用的是安装主题包时提供的默认设置:https://sitepackagebuilder.com)
根据评论,解决方案应该是将该部分添加到默认页面布局文件。
默认情况下(来自 sitepackagebuilder)使用布局文件,因此模板中定义的部分必须在布局文件中定义。
在默认布局文件中,您发现只有 "main" 部分被渲染。
要添加 Footer
部分,请在布局中的某处放置一个 RenderViewHelper
:
<f:render section="Footer" />
如果你想让它成为可选的,你可以将属性 optional="true"
添加到 ViewHelper,这样你就不必在不需要的每个模板中定义页脚部分。
FLUIDTEMPLATE 的结构如下所示:
Templates
可以包含Partials
并且可以有Sections
Partials
可以包含其他Partials
Layouts
包含Templates
可以渲染Sections
也可以包含Partials
如果您想为您的全局页面呈现页脚,请将页脚 Partial
放入您的 Layout
文件中。如果您想要一个取决于所使用模板的页脚,请将页脚放在模板的 Section
中,然后在 Layout
.
Section
只是为了澄清 René 的回答:
流体模板:
templates - 这是流体的入口。如果调用流体,则调用模板 (
<f:layout name="layoutname" />
)。模板可以决定布局;如果这样做,渲染从布局开始layouts - 它们旨在提供一般结构。这可以通过从确定模板和/或部分中插入不同的部分来实现。
partials - 这些是您的页面将要构建的灵活构建块。每当你有一个可能更频繁出现的数据块,或者它本身就是一个单元时,从中提取一部分,这样你就可以重用它并构建你的流体。
部分 可以作为子块出现在模板和部分中。
如果您插入像 <f:render section="sectionname" />
这样的部分,该部分应该在当前文件中 - 除了布局,他们希望它们的部分在模板中。
如果您想从另一个文件中插入一个部分,您只能从部分文件中插入部分:<f:render section="sectionname" partial="partialname" />
。
如果省略部分名称,则插入整个部分 (<f:render partial="partialname" />
)
一般来说,所有带有 f:render
的插入都不会传输任何数据(流体变量),除了:布局获取确定模板已知的所有数据,并且模板中从布局插入的部分知道所有数据初始模板的数据。
对于所有其他插入,您可能需要使用 f:render
viewhelper 的 arguments
参数传输数据:
<f:render section="sectionname" arguments="{ind1:'data1', ind2:'data2'}" />
特殊情况:您可以使用 arguments="{_all}"
感谢 René Pflamm 和 Bernd Wilke 的解释。由于我来自 tpyo3 v6.2,我在那里使用标记记录在多个模板上重复相同的项目:
LOGO = RECORDS
LOGO.tables = tt_content
LOGO.source = 1
然后在模板中
<div class="myClass">###LOGO###</div>
这使我能够从 typo3 中的文件夹中获取一些与其 ID 匹配的元素。
我不知道这是否还能用,但我创建了一个简单的函数
(located at ext/your_theme/Configuration/Typoscript/Helper/DynamicContent.typoscript)
在我调用 typoscriptObjectPath="lib.dynamicContentFunction"
的部分中使用,这允许我通过数据参数调用我想要呈现的元素的 id。这是一个示例和函数:
<f:cObject typoscriptObjectPath="lib.dynamicContentFunction" data="{Uid: '11'}" />
和
lib.dynamicContentFunction = COA
lib.dynamicContentFunction {
5 = LOAD_REGISTER
5 {
Uid.cObject = TEXT
Uid.cObject {
field = Uid
}
}
20 = CONTENT
20 {
table = tt_content
select {
includeRecordsWithoutDefaultTranslation = 1
orderBy = sorting
where = {#uid}={register:Uid}
where.insertData = 1
pidInList = -1
recursive = 99
}
stdWrap {
dataWrap = {register:wrap}
required = 1
}
}
90 = RESTORE_REGISTER
}
警告:如果您有很多元素,这可能会影响您的网站速度。
另外,我想知道你们是怎么想的。有一个更好的方法吗?
目的:呈现在 typo3 中创建的确定内容元素,并可从那里编辑,我可以通过 selecting 其 id 调用部分内容。如果可能,该函数必须通过数据参数从确定的错字 page/folder(id) 和 select 中搜索所需的内容元素。所以这样我就可以使用一个可编辑的页脚元素,例如在每个页面上重复。