【问题标题】:Drupal Custom Theme Missing CSSDrupal 自定义主题缺少 CSS
【发布时间】:2016-05-11 19:49:01
【问题描述】:

我正在让一个 Drupal 站点在我的本地主机上工作。目前,它似乎输出了一些内容(数据库正在运行),但没有任何样式。

当我查看源代码时,我看到了:

 <link type="text/css" rel="stylesheet" href="http://localhost:88/sites/MAA/" media="all" />
<link type="text/css" rel="stylesheet" href="http://localhost:88/sites/MAA/" media="all" />
<link type="text/css" rel="stylesheet" href="http://localhost:88/sites/MAA/" media="all" />
<link type="text/css" rel="stylesheet" href="http://localhost:88/sites/MAA/" media="screen" />
<link type="text/css" rel="stylesheet" href="http://localhost:88/sites/MAA/" media="all" />
<link type="text/css" rel="stylesheet" href="http://localhost:88/sites/MAA/" media="all" />
<link type="text/css" rel="stylesheet" href="http://localhost:88/sites/MAA/" media="all" />
<link type="text/css" rel="stylesheet" href="http://localhost:88/sites/MAA/" media="print" />
<link type="text/css" rel="stylesheet" href="http://localhost:88/sites/MAA/" media="all" />
  <script type="text/javascript" src="http://localhost:88/sites/MAA/sites/all/modules/jquery_update/replace/jquery/1.8/jquery.min.js?v=1.8.3"></script>

也就是说,除了网站的路径部分外,不包含模板的 CSS。现在,.info 文件如下:

; Stylesheets. Anything within the "framework" folder will be placed before all others.
stylesheets[all][] = styles/framework/reset.css
stylesheets[all][] = styles/framework/text.css
stylesheets[all][] = styles/framework/960.css
stylesheets[all][] = styles/framework/debug.css
stylesheets[all][] = styles/css/css_hides.css

; Theme specific styles. Any sub-themes should override this.
stylesheets[all][] = styles/skin.css
stylesheets[all][] = styles/maa.css
stylesheets[all][] = styles/maa-legacy.css
stylesheets[all][] = styles/jq-ui-date-range-picker/ui.daterangepicker.css
stylesheets[all][] = styles/styles_nvl.css
stylesheets[all][] = styles/css_hides.css
stylesheets[print][] = styles/print.css

; Theme specific scripts.
scripts[] = "js/enlargeit.js"
scripts[] = "js/jquery-ui.js"
scripts[] = "js/custom.js"

regions[page_top]              = Page top
regions[header]                = Header
regions[search_box]            = Search Box
regions[main_nav]              = Main Navigation
regions[highlighted]           = Highlight
regions[featured]              = Featured
regions[help]                  = Help
regions[home_content]          = Home Content
regions[home_content_bottom]   = Home Content Bottom
regions[content]               = Content
regions[sidebar_first]         = Left sidebar
regions[sidebar_second]        = Right sidebar
regions[footer_top]            = Footer Top
regions[footer_top_left]       = Footer Top Left
regions[footer_top_center_one] = Footer Top Center 1
regions[footer_top_center_two] = Footer Top Center 2
regions[footer_top_right]      = Footer Top Right
regions[footer_left]           = Footer Left
regions[footer_right]          = Footer Right
regions[page_bottom]           = Page bottom

谁能告诉我应该去哪里解决这个问题?在 html.tpl.php 文件中,有一行输出样式,但是我找不到它的填充位置。

 <?php print $styles; ?>
 <?php print $scripts; ?>

【问题讨论】:

    标签: php html css drupal drupal-7


    【解决方案1】:

    解决任何 Drupal 问题的第一步: 您是否尝试过清除缓存? (在 Drupal 中相当于“你试过关闭它然后重新打开吗?”)

    如何清除缓存: 如果您以管理员身份登录该站点,请转到配置 > 开发 > 性能。您应该会看到一个“清除所有缓存”按钮。

    如果这不起作用: 你查看过 Drupal 文档吗? https://www.drupal.org/node/171209

    如果您聚合和压缩 CSS 文件(配置 > 开发 > 性能中的设置)会发生什么?

    【讨论】:

    • 我似乎无法执行任何这些操作,因为我无法登录。我得到的只是一个带有内容和非程式化菜单的首页。当我单击菜单中的条目时,会加载正确的页面,但保持未样式化。
    • 您有登录凭据吗? Drush 可以协助恢复凭据 - 在此处了解 Drush:drupal.org/drush-faq 这是下载链接:docs.drush.org/en/master 这是一个可以执行 drupal 管理任务的命令行工具。作为管理员,您需要在界面中或从命令行执行一些操作——其中之一是清除缓存。出于性能原因,Drupal 作为一个系统做了很多缓存。除非您说服它放弃缓存的信息,否则您不会看到您的更改。
    • 知道了。谢谢你。我要开始学习了。另外,我确实有登录凭据。也就是说,我从一个我拥有有效凭据的实时站点中转储了这个数据库。 Drupal 如何处理此类迁移是否存在某种特殊情况?
    • 您用于登录 mysite.com/user(或 mysite.com/?q=user,如果您没有启用干净的 URL)的凭据与站点使用的凭据不同与数据库进行通信。 Drush 可以帮助您恢复“user-1”管理员登录数据。 drushcommands.com/drush-7x/user/user-login
    • 最近几天我一直在玩 Drush。这似乎是一个很棒的工具!谢谢你。在这一点上,我决定放弃 Windows 的尝试,将整个站点转移到 Linux 服务器上。现在,我的首页加载了样式和链接,尽管缺少一些图像。但是,当我单击任何菜单时,我得到 Not Found The requested URL was not found on this server.
    【解决方案2】:

    我刚刚在将网站从生产环境克隆到本地计算机时遇到了这个问题。生产和暂存环境都很好,所以我开始对我的机器进行故障排除。

    在遇到此特定问题时,之前的答案绝对是很好的起点。然而,真正的罪魁祸首似乎是 Drupal 在注册样式表时如何使用文件系统。

    一般来说,您的html.tpl.php 文件将有一个$styles 变量。这是一个输出字符串,包含您在主题的.info 文件中注册的所有样式表。您可能有也可能没有预处理钩子来更改 template.php 文件中的 css 文件。

    在追溯所有这些并确认它是正确的之后,运行系统状态报告将帮助您确定需要解决的区域。在这个特定场景中,它是一个使用 ctools 模块的 Drupal 7 站点。登录后浏览/admin/reports/status 发现ctools 无法在/sites/default/files/ctools/ 中创建正确的目录。

    结果是,如果 Drupal 无法创建此目录,它将从我的样式表中删除 URI。驱动每个样式表输出的数据来自您的 .info 和任何添加 css 的预处理函数。

    我希望这可以帮助其他遇到此问题并摸不着头脑的人。

    【讨论】:

      猜你喜欢
      • 2023-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-03
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      相关资源
      最近更新 更多