0

我在 Typo3 Neos 中为一个网站创建了一个网站模板。但是,在模板中我需要定义 javascript 的顺序,因为 CSS 文件必须包含在 javascript 文件之前。我现在有这些文件:

默认.html:

{namespace neos=TYPO3\Neos\ViewHelpers}
{namespace ts=TYPO3\TypoScript\ViewHelpers}
<!DOCTYPE html>
<html lang="en">
<head>
    <f:section name="meta">
          <meta name="viewport" content="width=device-width, initial-scale=1.0">

        <meta name="description" content="">
        <meta name="author" content="">
    </f:section>

    <f:section name="stylesheets">
        <!-- Bootstrap CSS -->
        <link href="{f:uri.resource(path: 'css/bootstrap.css', package: 'MyApp')}" rel="stylesheet">
        <link href="{f:uri.resource(path: 'css/responsive.css', package: 'MyApp')}" rel="stylesheet">

        <!-- Plugins -->
        <link href="{f:uri.resource(path: 'plugins/flexslider/flexslider.css', package: 'MyApp')}" rel="stylesheet">

        <!-- Theme style -->
        <link href="{f:uri.resource(path: 'css/theme-style.css', package: 'MyApp')}" rel="stylesheet">
    </f:section>

    <f:section name="headScripts">
        <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
        <!--[if lt IE 9]>
        <script src="{f:uri.resource(path: 'js/html5.js', package: 'MyApp')}"></script>
        <![endif]-->

        <!--Retina.js plugin - @see: http://retinajs.com/-->
        <script src="{f:uri.resource(path: 'plugins/retina/retina.js', package: 'MyApp')}"></script> 
    </f:section>
</head>

和 Root.ts2:

page = Page {
head {

    meta = TYPO3.TypoScript:Template {
        templatePath = 'resource://MyApp/Private/Templates/Page/Default.html'
        sectionName = 'meta'
        title = ${q(node).property('title')}
    }

    stylesheets.site = TYPO3.TypoScript:Template {
        templatePath = 'resource://MyApp/Private/Templates/Page/Default.html'
        sectionName = 'stylesheets'
    }

    javascripts.site = TYPO3.TypoScript:Template {
        templatePath = 'resource://MyApp/Private/Templates/Page/Default.html'
        sectionName = 'headScripts'
    }
}

body {
    templatePath = 'resource://MyApp/Private/Templates/Page/Default.html'
    sectionName = 'body'
    parts {
        menu = Menu
        breadcrumb = Breadcrumb
    }
    // These are your content areas, you can define as many as you want, just name them and the nodePath.
    content {
        // The default content section
        main = PrimaryContent {
            nodePath = 'main'
        }
    }

    javascripts.site = TYPO3.TypoScript:Template {
        templatePath = 'resource://MyApp/Private/Templates/Page/Default.html'
        sectionName = 'bodyScripts'
    }
}
}

HTML 中的结果是:

<!DOCTYPE html><html><!--
	This website is powered by TYPO3 Neos, the next generation CMS, a free Open
	Source Enterprise Content Management System licensed under the GNU/GPL.

	TYPO3 Neos is based on Flow, a powerful PHP application framework licensed under the GNU/LGPL.

	More information and contribution opportunities at http://neos.typo3.org and http://flow.typo3.org
--><head>
        <meta charset="UTF-8" />
        <title>Home</title>
    
        <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
        <!--[if lt IE 9]>
        <script src="http://app.local/_Resources/Static/Packages/MyApp/js/html5.js"></script>
        <![endif]-->

        <!--Retina.js plugin - @see: http://retinajs.com/-->
        <script src="http://app.local/_Resources/Static/Packages/MyApp/plugins/retina/retina.js"></script>

        <!-- Bootstrap CSS -->
        <link href="http://app.local/_Resources/Static/Packages/MyApp/css/bootstrap.css" rel="stylesheet">
        <link href="http://app.local/_Resources/Static/Packages/MyApp/css/responsive.css" rel="stylesheet">

        <!-- Plugins -->
        <link href="http://app.local/_Resources/Static/Packages/MyApp/plugins/flexslider/flexslider.css" rel="stylesheet">

        <!-- Theme style -->
        <link href="http://app.local/_Resources/Static/Packages/MyApp/css/theme-style.css" rel="stylesheet">

 

        <meta name="viewport" content="width=device-width, initial-scale=1.0">

        <meta name="description" content="">
        <meta name="author" content="">
    

    </head><body>

但是,我希望元信息位于顶部,然后是样式表,最后是要包含的 javascript 文件。是否可以定义渲染元素的顺序?我希望使用 Default.html 的顺序,但似乎没有。

4

1 回答 1

1

错字脚本中有@position,您可以使用它来更改排序。要查看实际情况,请检查TYPO3.Neos/Resources/Private/TypoScript/Prototypes/Page.ts2. 在您的情况下,它应该可以工作:

meta.@position = 'start 5'
stylesheets.@position = 'start 10'
javascripts.@position = 'start 15'

或者您可以直接将其放入定义中:

meta = TYPO3.TypoScript:Template {
    @position = 'start 5'

你也可以使用 sth like 'after headTag'or 'before stylesheets'

关于 TypoScript - TypoScript 2 Pocket Reference值得检查 :)

于 2014-12-17T14:06:08.443 回答