英文:
TYPO3 custom content element template is not being rendered
问题
我正在尝试在TYPO3 v12中创建自己的内容元素,但其模板未被渲染。根据模板代码,应显示的HTML代码如下:
<header class="header">
<div class="af6bus__banner">Test</div>
</header>
然而,我得到的是:
<header class="header"></header>
我已经检查了typoscript是否包含在根页面中,这是正确的。我还尝试删除渲染注册,结果如预期,出现错误"内容元素没有渲染定义"。
以下是我的当前代码:
af6bus/Resources/Private/Layouts/Default.html
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
data-namespace-typo3-fluid="true">
<span class="anchor" id="top"></span>
<f:render section="content" />
</html>
af6bus/Resources/Private/Templates/Default.html
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
data-namespace-typo3-fluid="true">
<f:layout name="Default" />
<f:section name="content">
<header class="header">
<f:cObject typoscriptObjectPath="lib.dynamicContent" data="{colPos: '100'}" />
</header>
<main class="main">
<f:cObject typoscriptObjectPath="lib.dynamicContent" data="{colPos: '0'}" />
</main>
<a href="#top" class="scroll--top"></a>
<footer class="footer">
</footer>
</f:section>
</html>
af6bus/Resources/Private/Templates/Banner.html
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
data-namespace-typo3-fluid="true">
<f:layout name="Default" />
<f:section name="content">
<div class="af6bus__banner">Text</div>
</f:section>
</html>
af6bus/Configuration/TypoScript/Setup/template.typoscript
page = PAGE
page {
10 = FLUIDTEMPLATE
10 {
templateName = TEXT
templateName.stdWrap {
cObject = CASE
cObject {
key.data = pagelayout
default = TEXT
default.value = Default
pagets__default = TEXT
pagets__default.value = Default
pagets__nobanner = TEXT
pagets__nobanner.value = NoBanner
}
}
layoutRootPaths {
10 = EXT:af6bus/Resources/Private/Layouts/
}
templateRootPaths {
10 = EXT:af6bus/Resources/Private/Templates/
}
partialRootPaths {
10 = EXT:af6bus/Resources/Private/Partials/
}
variables {
siteName = TEXT
siteName.value = {siteLanguage:websiteTitle}
siteName.insertData = 1
homePid = TEXT
homePid.value = {$homePid}
footerPid = TEXT
footerPid.value = {$footerPid}
}
}
}
lib.dynamicContent = COA
lib.dynamicContent {
10 = LOAD_REGISTER
10.colPos.cObject = TEXT
10.colPos.cObject {
field = colPos
ifEmpty.cObject = TEXT
ifEmpty.cObject {
value.current = 1
ifEmpty = 0
}
}
20 = CONTENT
20 {
table = tt_content
select {
orderBy = sorting
where = {#colPos}={register:colPos}
where.insertData = 1
}
}
90 = RESTORE_REGISTER
}
## Banner-Template
tt_content {
af6bus_banner =< lib.dynamicContent
af6bus_banner {
templateName = Banner.html
dataProcessing {
10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
10 {
references.fieldName = assets
}
}
}
}
希望这可以帮助你解决问题。
英文:
I'm trying to create my own content element in TYPO3 v12, but the template of it is not being rendered. Based on the template code, the HTML code that should be displayed would look like this:
<header class="header">
<div class="af6bus__banner">Test</div>
</header>
However, what I'm getting is:
<header class="header"></header>
I've checked if the typoscript is included in the root page, which was the case. I've also tried removing the rendering registration which resultet, as expected, in the error "content element has no rendering definition".
Here is my current code:
af6bus/Resources/Private/Layouts/Default.html
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
data-namespace-typo3-fluid="true">
<span class="anchor" id="top"></span>
<f:render section="content" />
</html>
af6bus/Resources/Private/Templates/Default.html
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
data-namespace-typo3-fluid="true">
<f:layout name="Default" />
<f:section name="content">
<header class="header">
<f:cObject typoscriptObjectPath="lib.dynamicContent" data="{colPos: '100'}" />
</header>
<main class="main">
<f:cObject typoscriptObjectPath="lib.dynamicContent" data="{colPos: '0'}" />
</main>
<a href="#top" class="scroll--top"></span></a>
<footer class="footer">
</footer>
</f:section>
</html>
af6bus/Resources/Private/Templates/Banner.html
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
data-namespace-typo3-fluid="true">
<f:layout name="Default" />
<f:section name="content">
<div class="af6bus__banner">Text</div>
</f:section>
</html>
af6bus/Configuration/TypoScript/Setup/template.typoscript
page = PAGE
page {
10 = FLUIDTEMPLATE
10 {
templateName = TEXT
templateName.stdWrap {
cObject = CASE
cObject {
key.data = pagelayout
default = TEXT
default.value = Default
pagets__default = TEXT
pagets__default.value = Default
pagets__nobanner = TEXT
pagets__nobanner.value = NoBanner
}
}
layoutRootPaths {
10 = EXT:af6bus/Resources/Private/Layouts/
}
templateRootPaths {
10 = EXT:af6bus/Resources/Private/Templates/
}
partialRootPaths {
10 = EXT:af6bus/Resources/Private/Partials/
}
variables {
siteName = TEXT
siteName.value = {siteLanguage:websiteTitle}
siteName.insertData = 1
homePid = TEXT
homePid.value = {$homePid}
footerPid = TEXT
footerPid.value = {$footerPid}
}
}
}
lib.dynamicContent = COA
lib.dynamicContent {
10 = LOAD_REGISTER
10.colPos.cObject = TEXT
10.colPos.cObject {
field = colPos
ifEmpty.cObject = TEXT
ifEmpty.cObject {
value.current = 1
ifEmpty = 0
}
}
20 = CONTENT
20 {
table = tt_content
select {
orderBy = sorting
where = {#colPos}={register:colPos}
where.insertData = 1
}
}
90 = RESTORE_REGISTER
}
## Banner-Template
tt_content {
af6bus_banner =< lib.dynamicContent
af6bus_banner {
templateName = Banner.html
dataProcessing {
10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
10 {
references.fieldName = assets
}
}
}
}
答案1
得分: 0
经过一些试验和错误,我终于让它工作了。现在我不确定这是否是理想的解决方案,但它可以工作。
在我的TypoScript文件 af6bus/Configuration/TypoScript/Setup/template.typoscript 中,我调整了渲染并将 lib.dynamicContent 替换为 lib.contentElement。我还从模板名称中移除了 .html。代码现在看起来是这样的。
tt_content {
af6bus_banner < lib.contentElement
af6bus_banner {
templateName = Banner
templateRootPaths.100 = EXT:af6bus/Resources/Private/Templates/
dataProcessing {
10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
10 {
references.fieldName = assets
}
}
}
}
至于模板,我只是将部分名称从 content 更改为 Main。
英文:
So after some trial and error I have finally made it work. Now I'm not sure wether or not this is the ideal solution, but it works.
In my TypoScript file af6bus/Configuration/TypoScript/Setup/template.typoscript I adjusted the rendering and replaced lib.dynamicContent with lib.contentElement. I also removed the .html from the template name. This is how the code looks now.
tt_content {
af6bus_banner =< lib.contentElement
af6bus_banner {
templateName = Banner
templateRootPaths.100 = EXT:af6bus/Resources/Private/Templates/
dataProcessing {
10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
10 {
references.fieldName = assets
}
}
}
}
As for the template, I simply changed the section name from content to Main.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论