0

试图理解在typo3中做模板的正确方法,我从typo3 6.2到typo3 v9.5,一切都是新的。我已经实现了使用 DCE,创建了一个后端布局,现在我正在尝试创建一个重复的元素,以便在具有不同模板的多个页面上使用。

将新的typo3安装与typo3提供的主模板进行比较,我可以看到他们在里面使用了一个文件

ext/your_template/Resources/Private/Partials/Page/Structure/Footercontent

然后在模板中,他们渲染从主模板加载元素的 html 文件(我猜)。

在这里你可以看到渲染

当我尝试在自己的页面中复制它时,我的问题就出现了。它不会呈现在我的页面中,甚至不会呈现在 html 基础结构中。

我在这张图片中显示的FooterContent.html 和我的主模板中的渲染调用就像在这张图片中

Home.html(模板)

  <f:section name="Footer">

      <f:render partial="Structure/FooterContent" arguments="{_all}" />

  </f:section>

页脚内容.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 )

4

3 回答 3

1

从评论中,解决方案应该是将该部分添加到默认页面布局文件中。

默认情况下(来自sitepackagebuilder)使用布局文件,因此模板中定义的部分必须在布局文件中定义。

在默认布局文件中,您只会找到一个渲染的“主”部分。

要添加该Footer部分,RenderViewHelper请在布局中放置一个:

<f:render section="Footer" />

如果你想让它成为可选的,你可以将属性添加optional="true"到 ViewHelper 中,这样如果你不需要这个,你就不必在每个模板中定义页脚部分。

FLUIDTEMPLATE 的结构如下所示:

  • Templates可以包含Partials并且可以拥有Sections
  • Partials可以包含其他Partials
  • Layouts包含Templates可以渲染Sections并且还可以包含Partials

如果要为全局页面呈现页脚,请将页脚Partial放在Layout文件中。如果您想要一个取决于使用的模板的页脚,请将页脚放在Section模板的 a 中,然后SectionLayout.

于 2018-11-07T15:40:52.657 回答
1

只是为了澄清勒内的回答:

流体模板:

  • 模板- 这是进入流体的入口。如果调用流体,则调用模板 ( <f:layout name="layoutname" />)。一个模板可以决定一个布局;如果这样做,则从布局开始渲染

  • 布局- 它们旨在提供一般结构。这可以通过从确定模板和/或部分插入不同的部分来实现。

  • 部分- 这些是您的页面将构建的灵活构建块。每次你有一个可能更频繁出现的数据块,或者它本身就是一个单元时,从它中提取一部分,这样你就可以重用它并构建你的流体。

部分可以作为子块出现在模板和部分中。
如果您插入部分,例如<f:render section="sectionname" />该部分应该在当前文件中 - 除了布局,他们希望它们的部分在模板中。
如果你想从另一个文件插入一个部分,你只能从一个部分插入部分:<f:render section="sectionname" partial="partialname" />. 如果省略部分名称,则插入整个部分 ( <f:render partial="partialname" />)

通常,所有插入f:render不传输数据(流体变量),除了:布局获取确定模板已知的所有数据,并且从布局插入的模板中的部分知道初始模板的所有数据。
对于所有其他插入,您可能需要使用viewhelper 的arguments参数传输数据:f:render

<f:render section="sectionname" arguments="{ind1:'data1', ind2:'data2'}" />

一种特殊情况:您可以使用以下命令传输所有(本地已知的)数据arguments="{_all}"

于 2018-11-08T06:39:35.770 回答
0

感谢 René Pflamm 和 Bernd Wilke 的解释。由于我来自 tpyo3 v6.2,因此我在那里使用标记记录在多个模板上重复相同的项目:

LOGO = RECORDS
LOGO.tables = tt_content
LOGO.source = 1

然后在模板中

<div class="myClass">###LOGO###</div>

这让我可以从typo3 中的一个文件夹中获取一些与其id 相匹配的元素。

我不知道这是否仍然可以使用,但我创建了一个简单的功能

(位于 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中创建的确定的内容元素,并且可以从那里编辑,我可以通过选择他们的id来调用部分内容。如果可能,该函数必须从确定的错别字页面/文件夹(id)中搜索并通过数据参数选择所需的内容元素。所以这样我就可以使用一个可编辑的页脚元素,例如在每一页上重复。

于 2018-11-08T09:14:36.780 回答