2017-01-11 30 views
1

Drupal 8のカスタムモジュールにCSSファイルを含めることができます。すでに1つのルーティングパスと1つのコントローラ機能を持つ別のモジュールがあり、新しいモジュールではそうではありません。何かが間違っているのですか、複数のルーティングパスで何か違うのですか?複数のルーティングを持つDrupal 8カスタムモジュールにCSSファイルを組み込みます

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' 

私はsupport_changesの出力のためのCSSを含めます。

module.library.yml

module.support_requests: 
    css: 
    theme: 
     src/css/modulestyle.css: {} 

そして最後に、私は自分のコントローラに含めます。

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 

} 

答えて

1

ためのrouting.ymlとlibrary.ymlファイルで同じキー "module.support_requests" の紛争であってもよいです。 $ [ '添付#'] [ 'ライブラリ'] [] = 'モジュール/ support_requests' を構築として "support_requests" へmodule.library.ymlでキーを変更してみてください、ライブラリを追加します。

+0

努力してくれてありがとうございましたが、しばらく前に解決策を見つけました。それはタイプミスでした:それはlibraries.ymlでなければなりません。 drupalはこの静的を必要とします。 – Gabbax0r

関連する問題