2017-10-04 17 views
0

Drupal 8でページタイトルをプログラムで変更して、テーマファイルにハードコードされるようにしたい。Drupal 8 - フックを変更するページタイトル

私はpreprocess_page_titleにフック機能を使用しようとしていますが、タイトルを変更するページがわからないようです。ここで

は、私がこれまで持っているものです。

function test_preprocess_page_title(&$variables) { 
    if (arg(0) == 'node/12') { 
    $variables['title'] = 'New Title'; 
    } 
} 

私は1つの特定のページに、この変更を行うための唯一の方法は、ノードの引数を設定することです考え出し。誰かがDrupalのページタイトルを無効にする方法を見つけましたか?

答えて

1

ここで前処理あなたのページへの方法です:あなたtemplate.themeファイルで

function yourthemename_preprocess_page(&$variables) { 
    $node = \Drupal::routeMatch()->getParameter('node'); 
    if ($node) { 
    $variables['title'] = $node->getTitle(); 
    } 
} 

とテンプレートのpage.html.twigで

{{title}} 
1

プリプロセッサを追加し、ページのタイトルをオーバーライドするには以下のように、変数を印刷してお使いのテンプレートフォルダに.html.twig:

function theme_preprocess_page_title(&$variables) { 
    $node = \Drupal::request()->attributes->get('node'); 
    $nid = $node->id(); 
    if($nid == '14') { 
    $variables['subtitle'] = 'Subheading'; 
    } 
} 

次に{{字幕}}

関連する問題