我在实现我的网站时正在慢慢学习 D8,并决定按照https://www.webwash.net/how-to-create-powerful-container-paragraphs-in-drupal-8/开始我的登录页面。
开始 hook_preprocess 部分,我假设这会进入:
主题/MYBOOTSTRAPSUBTHEME/MYTHEMENAME.theme
<?php
/**
* @file
* Bootstrap sub-theme.
*
* Place your custom PHP code in this file.
*/
function MYSUBTHEMENAME_preprocess_paragraph__banner(&$variables) {
$paragraph = $variables['paragraph'];
if (!$paragraph->field_image->isEmpty()) {
$image = $paragraph->field_image->entity->url();
$variables['attributes']['style'][] = 'background-image: url("' . $image . '");';
$variables['attributes']['style'][] = 'background-size: cover;';
$variables['attributes']['style'][] = 'background-position: center center;';
}
}
我没有运气从配置页面清除缓存。这是使用 MAMP (PHP 7.1.6) 构建的 localhost - 如果有任何用途。
我已经仔细检查了教程显示的所有配置,并且所有名称都正确(横幅、字段图像)。我似乎无法找到问题!
有什么建议么?