簡體   English   中英

Typo3 中未調用 RequireJS 回調

[英]RequireJS callback not called in Typo3

我們正在為更大的大學網站開發 Typo3 擴展,並且正在努力使用 RequireJS 在前端運行自定義 JavaScript 代碼。 當我們嘗試使用 RequireJS 加載我們的依賴項時,我們甚至無法獲得一個簡單的示例來工作。

We tried following the offical documentation https://docs.typo3.org/m/typo3/reference-coreapi/9.5/en-us/ApiOverview/JavaScript/RequireJS/Index.html , but we just cant get Test.say() (見下文)被調用。

我們的項目結構如下:

- Classes
  - (all our PHP code)
- Configuration
  - (AjaxRoutes, FlexForms and TCA) 
- Ressources
  - Private
    - Templates
      - Modulelist
        - List.html
  - Public
    - JavaScript
      - ListFilter.js
- composer.json
- ext_emconf.php
- ext_localconf.php
- ext_tables.sql

列表.html:

<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers">
<!-- this is just some table filled by a controller -->
<table border="1" cellspacing="1" cellpadding="5">
    <tr>
        <td>Modulname</td>
        <td>OU Name</td>
        <td>ECTS</td>
    </tr>
    <f:for each="{modules}" as="module">
        <tr>
            <td align="top">{module.name}</td>
            <td align="top">
                <f:format.crop maxCharacters="100">{module.offeredBy.name}</f:format.crop>
            </td>
            <td align="top">{module.ects}</td>
        </tr>
    </f:for>
</table>

<!-- our extension is named DemoExtension -->
<f:be.pageRenderer
    includeRequireJsModules="{
        0:'TYPO3/CMS/DemoExtension/ListFilter'
    }"
/>
</html>

ListFilter.js:

console.log("ListFilter.js loaded");
define(['jquery', 'TYPO3/CMS/Core/DocumentService'], function($, DS) {
    console.log("List.html inside define");
    var Test = {
        message: "test"
    };

    Test.say = function() {
        alert(Test.message);
    };

    $(document).ready(function() {
        console.log("List.html inside define, jQ callback");
        Test.say();
    });

    DS.ready().then(() => {
        console.log("List.html inside define, DS callback");
        Test.say();
    });

    return Test;
});

但是,在加載相應頁面時,控制台僅打印以下行:

ListFilter.js loaded

我們用谷歌搜索了很多,但無法讓它工作。 我們缺少什么?

TYPO3 默認不會在前端加載任何 Javascript。

您的前端呈現的內容由您的模板(排版/流體)定義

您可能正在尋找 page.includeJS 或類似的配置。 但是最好的方法可以非常廣泛地取決於您如何呈現您的前端以及您在您的網站中擁有哪些其他擴展,例如 vhs/flux

有關 PAGE OBJECT https://docs.typo3.org/m/typo3/reference-typoscript/master/en-htmlSetup///master/en-html/

你真的加載了RequireJS嗎?

PageRenderer中 TYPO3 中的特殊 RequireJS 支持僅適用於后端。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM