• <tfoot id='Lx45U'></tfoot>

      <bdo id='Lx45U'></bdo><ul id='Lx45U'></ul>
  • <small id='Lx45U'></small><noframes id='Lx45U'>

    <legend id='Lx45U'><style id='Lx45U'><dir id='Lx45U'><q id='Lx45U'></q></dir></style></legend>

      1. <i id='Lx45U'><tr id='Lx45U'><dt id='Lx45U'><q id='Lx45U'><span id='Lx45U'><b id='Lx45U'><form id='Lx45U'><ins id='Lx45U'></ins><ul id='Lx45U'></ul><sub id='Lx45U'></sub></form><legend id='Lx45U'></legend><bdo id='Lx45U'><pre id='Lx45U'><center id='Lx45U'></center></pre></bdo></b><th id='Lx45U'></th></span></q></dt></tr></i><div id='Lx45U'><tfoot id='Lx45U'></tfoot><dl id='Lx45U'><fieldset id='Lx45U'></fieldset></dl></div>

      2. 如何在 Drupal 8 主题中添加 javascript 库?

        时间:2023-06-22
          <tbody id='MOQUj'></tbody>
        <legend id='MOQUj'><style id='MOQUj'><dir id='MOQUj'><q id='MOQUj'></q></dir></style></legend>

              <i id='MOQUj'><tr id='MOQUj'><dt id='MOQUj'><q id='MOQUj'><span id='MOQUj'><b id='MOQUj'><form id='MOQUj'><ins id='MOQUj'></ins><ul id='MOQUj'></ul><sub id='MOQUj'></sub></form><legend id='MOQUj'></legend><bdo id='MOQUj'><pre id='MOQUj'><center id='MOQUj'></center></pre></bdo></b><th id='MOQUj'></th></span></q></dt></tr></i><div id='MOQUj'><tfoot id='MOQUj'></tfoot><dl id='MOQUj'><fieldset id='MOQUj'></fieldset></dl></div>

              • <tfoot id='MOQUj'></tfoot>

              • <small id='MOQUj'></small><noframes id='MOQUj'>

                • <bdo id='MOQUj'></bdo><ul id='MOQUj'></ul>
                  本文介绍了如何在 Drupal 8 主题中添加 javascript 库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我试图在我正在构建的 Drupal 8 主题中包含一个自定义 javascript 文件来操作我的菜单.我按照 Drupal 8 主题指南中的说明进行操作,将其包含在我的 .info.yml 文件中:

                  I'm attempting to include a custom javascript file to manipulate my menu's in the Drupal 8 theme I am building. I followed the instructions in the Drupal 8 themeing guide, including it in my .info.yml file:

                  #js libraries
                  libraries:
                  - dcf/base
                  

                  并在我的 .libraries.yml 文件中定义它:

                  and defining it in my .libraries.yml file:

                  base:
                  version: 1.x
                  js:
                      js/endscripts.js
                  dependencies:
                      - core/drupal
                      - core/underscore
                      - core/backbone
                      - core/jquery
                  

                  最后创建一个带有钩子实现的 .theme 文件(我不是真正的 PHP 开发人员,所以我主要是从指南中的示例中进行复制/粘贴工作)

                  and finally creating a .theme file with a hook implementation (I'm not really a PHP developer, so I mostly did a copy/paste job from the example in the guide)

                  <?php
                  
                  function dcf_page_alter(&$page) { 
                    $page['#attached']['library'][] = 'dcf/base';
                  }
                  
                  ?>
                  

                  我清除缓存,注销以查看未登录的页面(管理视图有很多额外的脚本和它调用的 css 文件)并查看源代码以查看我的脚本是否正在加载.我在库中列出的所有依赖项都被加载,但不是我的脚本本身.

                  I clear the cache, log off to see the non-logged-in page (the admin view has a LOT of extra scripts and css files that it calls) and look at the source to see if my script is being loaded. All of the dependencies I listed in my library are being loaded, but not my script itself.

                  脚本本身只是一个基本测试,它应该使用 JQuery 隐藏我的主菜单,将主题设置为主题指南提到的严格"格式是必需的.

                  The script itself is just a basic test that should hide my main menu using JQuery, put into the 'strict' format the themeing guide mentions is required.

                  (function () {
                    "use strict";
                    // Custom javascript
                    $(document).ready(function() {
                      $("#block-dcf-main-menu").hide();
                    });
                  })();
                  

                  此时我不知所措.我的直觉是错误在于我的钩子实现,因为我真的不了解 Drupal 的钩子系统,但据我所知,它仍然可能只是他们还没有为 Drupal 8 实现这个(我这样做是为了为我的组织即将进行的网站重建测试 Drupal 8,并且我目前正在运行 Drupal 8.0.x-beta2,但未安装其他模块)

                  I'm at a loss at this point. My instinct is that the mistake is in my hook implementation, because I really don't understand Drupal's hook system, but as far as I can tell, it could still just be that they haven't finished implementing this yet for Drupal 8(I'm doing this to test Drupal 8 for my organizations upcoming website rebuild, and am currently running Drupal 8.0.x-beta2 with no additional modules installed)

                  推荐答案

                  答案,如来自 clive 的评论一样,是脚本末尾缺少的 {}.所以 mytheme.libraries.yml 中的脚本声明应该是
                  js:js/endscripts:{}

                  The answer, as in the comment from clive was the missing {} at the end of the script. So the script declaration in mytheme.libraries.yml should be
                  js: js/endscripts: {}

                  这篇关于如何在 Drupal 8 主题中添加 javascript 库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如果管理员或用户具有特定角色,则 Drupal 条件 PHP 下一篇:当有人在论坛主题上发帖时的 Drupal 电子邮件

                  相关文章

                  1. <i id='I15sQ'><tr id='I15sQ'><dt id='I15sQ'><q id='I15sQ'><span id='I15sQ'><b id='I15sQ'><form id='I15sQ'><ins id='I15sQ'></ins><ul id='I15sQ'></ul><sub id='I15sQ'></sub></form><legend id='I15sQ'></legend><bdo id='I15sQ'><pre id='I15sQ'><center id='I15sQ'></center></pre></bdo></b><th id='I15sQ'></th></span></q></dt></tr></i><div id='I15sQ'><tfoot id='I15sQ'></tfoot><dl id='I15sQ'><fieldset id='I15sQ'></fieldset></dl></div>
                      <bdo id='I15sQ'></bdo><ul id='I15sQ'></ul>
                    <legend id='I15sQ'><style id='I15sQ'><dir id='I15sQ'><q id='I15sQ'></q></dir></style></legend>
                    <tfoot id='I15sQ'></tfoot>

                    <small id='I15sQ'></small><noframes id='I15sQ'>