TYPO3自定义内容元素模板未被渲染。

huangapple go评论49阅读模式
英文:

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:

&lt;header class=&quot;header&quot;&gt;     
&lt;div class=&quot;af6bus__banner&quot;&gt;Test&lt;/div&gt;
&lt;/header&gt;

However, what I'm getting is:

&lt;header class=&quot;header&quot;&gt;&lt;/header&gt;

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

&lt;html xmlns:f=&quot;http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers&quot;
data-namespace-typo3-fluid=&quot;true&quot;&gt;
&lt;span class=&quot;anchor&quot; id=&quot;top&quot;&gt;&lt;/span&gt;
&lt;f:render section=&quot;content&quot; /&gt;
&lt;/html&gt;

af6bus/Resources/Private/Templates/Default.html

&lt;html xmlns:f=&quot;http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers&quot;
data-namespace-typo3-fluid=&quot;true&quot;&gt;
&lt;f:layout name=&quot;Default&quot; /&gt;
&lt;f:section name=&quot;content&quot;&gt;
&lt;header class=&quot;header&quot;&gt;
&lt;f:cObject typoscriptObjectPath=&quot;lib.dynamicContent&quot; data=&quot;{colPos: &#39;100&#39;}&quot; /&gt;
&lt;/header&gt;
&lt;main class=&quot;main&quot;&gt;
&lt;f:cObject typoscriptObjectPath=&quot;lib.dynamicContent&quot; data=&quot;{colPos: &#39;0&#39;}&quot; /&gt;
&lt;/main&gt;
&lt;a href=&quot;#top&quot; class=&quot;scroll--top&quot;&gt;&lt;/span&gt;&lt;/a&gt;
&lt;footer class=&quot;footer&quot;&gt;
&lt;/footer&gt;
&lt;/f:section&gt;
&lt;/html&gt;

af6bus/Resources/Private/Templates/Banner.html

&lt;html xmlns:f=&quot;http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers&quot;
data-namespace-typo3-fluid=&quot;true&quot;&gt;
&lt;f:layout name=&quot;Default&quot; /&gt;
&lt;f:section name=&quot;content&quot;&gt;
&lt;div class=&quot;af6bus__banner&quot;&gt;Text&lt;/div&gt;
&lt;/f:section&gt;
&lt;/html&gt;

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 =&lt; 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 =&lt; 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.

huangapple
  • 本文由 发表于 2023年7月7日 01:44:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76631342.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定