2016-08-30 4 views
0

간단한 모듈을 만드는 방법 drupal8 Google 태그와 같은 작은 JS 코드를 특정 페이지에 추가합니다.Drupal 8 모듈 만들기

대부분의 경우 관리자 설정에서 특정 페이지 옵션을 선택합니다.

답변

0

모듈에 mymodule.libraries.yml을 만듭니다. 그런 다음

mymodule.base: 
    version: 1.0.0 
    js: 
    js/your-javascript.js: {} 

우리 hook_page_attachments

function photography_page_attachments(array &$page) { 
    // Check the request URI or Path to decide if you want to show the library 
    // 
    // You may use: 
    // 1. \Drupal::service('path.current')->getPath() 
    // 2. \Drupal::request()->getRequestUri(); 
    // 
    $page['#attached']['library'][] = 'mymodule/mymodule.base'; 
}