未将Colorbox JS和CSS添加到所有页面中

问题描述 投票:0回答:1

我已经在基于Drupal 8的站点上设置了一个Colorbox模块,我发现它不适用于每种内容类型,因为与Colorbox相关的CSS和JS文件并未包含在所有页面中。

我有两种不同的内容类型,我们称其为GOOD和BAD。两者都有在标准html.html.twig模板中呈现并使用该<js-placeholder token="{{ placeholder_token }}">

的CSS和JS

[它们之间唯一的区别是,在GOOD内容类型中,有一个公共的Image字段,我在其中将Colorbox设置为视图“处理程序”,而在BAD模板中,将在其代码内创建Image。因此,我在等效元素(<a class="colorbox .." rtc.)中添加了CSS类,但问题是BAD输出html中没有链接的Colorbox JS文件。

GOOD的示例put(缩短):

<!-- BEGIN OUTPUT from 'themes/cav/templates/html.html.twig' -->


<!DOCTYPE html>
<html lang="cs" dir="ltr" prefix="og: http://ogp.me/ns#">
  <head>
...
<link rel="stylesheet" media="all" href="/core/modules/quickedit/css/quickedit.icons.theme.css?q01vyb" />
<link rel="stylesheet" media="all" href="/core/themes/seven/css/components/quickedit.css?q01vyb" />
<link rel="stylesheet" media="all" href="/modules/colorbox/styles/plain/colorbox_style.css?q01vyb" />
<link rel="stylesheet" media="all" href="/core/modules/toolbar/css/toolbar.theme.css?q01vyb" />
...

和来自BAD:

<!-- BEGIN OUTPUT from 'themes/cav/templates/html.html.twig' -->


<!DOCTYPE html>
<html lang="cs" dir="ltr" prefix="og: http://ogp.me/ns#">
  <head>
    <meta charset="utf-8" />
...
<link rel="stylesheet" media="all" href="/core/modules/quickedit/css/quickedit.icons.theme.css?q01ykj" />
<link rel="stylesheet" media="all" href="/core/themes/seven/css/components/quickedit.css?q01ykj" />
<link rel="stylesheet" media="all" href="/core/modules/toolbar/css/toolbar.theme.css?q01ykj" />
...

我不知何故,与Colorbox相关的那些JS和CSS文件没有链接到BAD,因为我没有在BAD内容类型内“设置Colorbox”(因为我没有正式的图像字段,所以我不能这样做),但是有什么方法可以“增强”其他方式将它们添加到页面中吗?

谢谢。TC

php drupal-8 colorbox drupal-theming drupal-templates
1个回答
0
投票

Colorbox以及所有模块和库仅在必要时加载(因为它是字段格式化程序,因此仅当您以该格式显示该字段时才加载)。这是仅向浏览器发送必要代码的默认行为。您可以使用https://www.drupal.org/project/colorbox_inline模块在每个页面中加载Colorbox。

© www.soinside.com 2019 - 2024. All rights reserved.