如何在Magento 2.1.8中显示自定义模块的模板-不起作用

时间:2019-05-14 17:38:56

标签: magento magento2.1 magento-layout-xml

这是Magento 2.1.8的自定义模块,其思想是通过“管理”面板控制带有嵌入式youtube视频的iframe。基本上允许-全屏,控件,自动播放等。

我希望此模板加载到我网站上的每个可能的页面

所有这些:

magento setup:upgrade
magento setup:di:compile
magento setup:static-content:deploy
magento cache:clean
magento cache:flush
magento indexer:reindex

我有 layouts / default.xml ,其中:

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="after.body.start">
            <block class="Magento\Framework\View\Element\Template" template="Mycompany_YouTube::youtube_configuration.phtml" name="mycompany.youtube.configuration" after="-" />
        </referenceContainer>
    </body>
</page>

templates / youtube_configuration.phtml

<?php

$config = [
        'youtube_config' => [
                "_force" => $this->helper('Mycompany\\Youtube\\Helper\\Data')->getConfig('youtube/general/_force'),
                "rel" => $this->helper('Mycompany\\Youtube\\Helper\\Data')->getConfig('youtube/general/rel'),
                "fs" => $this->helper('Mycompany\\Youtube\\Helper\\Data')->getConfig('youtube/general/fs'),
                "loop" => $this->helper('Mycompany\\Youtube\\Helper\\Data')->getConfig('youtube/general/loop'),
                "autoplay" => $this->helper('Mycompany\\Youtube\\Helper\\Data')->getConfig('youtube/general/autoplay'),
                "controls" => $this->helper('Mycompany\\Youtube\\Helper\\Data')->getConfig('youtube/general/controls'),
        ]
];

?>

<div id="Mycompany_YouTube" data-mage-init="<?= json_encode($config) ?>">
 <script type="text/javascript">
    console.log("Mycompany_YouTube Loaded!");
    define(["jquery"], function($) {
        "use strict";
        return function(config) {
            var params = config.youtube_config;

            if (params._force) {
                delete params._force;
                $('iframe[src*="youtube.com/embed"]').each(function(k,v) {
                   "mycompany";
                    var url = document.createElement('a');url.href = v.src;
                    url.search = $.param(params);
                    $(v).prop('src', url.href)
                });
            }
        }
    });
 </script>
</div>

模板未加载任何内容...

注意: 使用Magento 2.1.8(目前我只能使用的唯一选择就是问为什么)

我也处于开发人员模式

Magento的 前端 ,我也遇到问题

还请记住,我正在使用 以下树

/
|---/app
| |---/code
| | |---/Mycompany
| | | |---/YouTube
| | | | |---registration.php
| | | | |---/etc
| | | | | |---module.xml
| | | | | |---/adminhtml
| | | | | | |---config.xml
| | | | | | |---system.xml
| | | | |---/Helper
| | | | | |---Data.php
| | | | |---/view
| | | | | |---/frontend
| | | | | | |---requirejs-config.js
| | | | | | |---/layout
| | | | | | | |---default.xml
| | | | | | |---/templates
| | | | | | | |---youtube_configuration.phtml

我需要的最小结果是,刷新页面时,我可以在检查器中的模板中看到代码。

1 个答案:

答案 0 :(得分:0)

问题是我没有包含PSR-4自动装带器的composer.json。