[英]Include CSS file in Drupal 8 custom module with multiple routings
I would like to include a CSS file into my custom module in Drupal 8. I already have another module with only one routing path and one controller function and my CSS works fine there, but not so in the new module. 我想在Drupal 8的自定义模块中包含一个CSS文件。我已经有了另一个仅具有一个路由路径和一个控制器功能的模块,而我的CSS在那里工作得很好,但是在新模块中却没有。 Do I miss something, or is there anything different with multiple routing paths? 我会错过什么吗,还是多个路由路径有什么不同?
module.routing.yml
: module.routing.yml
:
module.support_bugs:
path: '/support/bugs'
defaults:
_controller: '\Drupal\module\Controller\moduleController::bugsShow'
_title: ''
requirements:
_permission: 'support_bugs'
module.support_requests:
path: '/support/requests/{param1}'
defaults:
_controller: '\Drupal\module\Controller\moduleController::requestsShow'
_title: ''
param1: null
requirements:
_permission: 'support_requests'
module.support_docs:
path: '/support/docs'
defaults:
_controller: '\Drupal\module\Controller\moduleController::docsShow'
_title: ''
requirements:
_permission: 'support_docs'
I want to include the CSS for the output of support_changes
. 我想将CSS包含在support_changes
的输出中。
module.library.yml
: module.library.yml
:
module.support_requests:
css:
theme:
src/css/modulestyle.css: {}
And in the end, I include it in my controller. 最后,我将其包含在控制器中。
moduleController.php
: moduleController.php
:
namespace Drupal\module\Controller;
class moduleController {
//other functions
public static function requestsShow($filter=null){
//some code inhere
$build['content'] = array(
'#markup' => $output);
$build['#attached']['library'][] = 'module/module.support_requests';
return $build;
}
//other functions
}
May be because of the conflict in same key "module.support_requests" in routing.yml and library.yml files. 可能是由于routing.yml和library.yml文件中的相同键“ module.support_requests”中的冲突。 Try changing the key in module.library.yml into " support_requests " and add the library as $build['#attached']['library'][] = 'module/ support_requests '; 尝试将module.library.yml中的密钥更改为“ support_requests ”,并将库添加为$ build [' #attached '] ['library'] [] ='module / support_requests ';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.