1

概要

テーマの前処理関数の内部に値を追加して$variables['theme_hook_suggestions']いますが、私のテーマは提案を受け入れていません。私は健全な量の完全なキャッシュのクリアを行っているので、キャッシュは問題ではありません。

私の提案をテーマに選択してもらいたいのですが、何を試してもうまくいきません。

上記は私の問題の抽象的なバージョンであり、おそらくほとんどの人にとって役立つ解決策です。私の特定のセットアップの詳細な説明、私の問題のより具体的な説明、および私が試みた「解決策」(これは機能しません) が続きます。

あなたが私に与えることができるどんな助けも途方もないものであり、非常に感謝しています. ありがとうございました!

設定

私のtemplate.phpファイルには、次のコードがあります。

function MYTHEME_preprocess_user_profile(&$variables) {  
  $variables['profile'] = array(
    'top_section' => array(
      '#theme'  => 'profile_section',
      '#type' => 'top_section',
      'profile_section' => /* [several renderable elements] */,
    ),
    'bottom_section' => array(
      '#theme'  => 'profile_section',
      '#type' => 'bottom_section',
      'profile_section' => /* [several renderable elements] */,
    ),
  );
}

したがって、本質的に、このMYTHEME_preprocess_user_profile()関数は に割り当てられたいくつかのプロファイル セクションを作成します$variables['profile']

user-profile.tpl.php次に、テーマにテンプレート ファイルを設定します。Zen サブテーマを使用しているため、ファイルはテーマ ディレクトリ内の「templates」ディレクトリに格納されます。次のようになります。

<h1 class="title">user-profile.tpl.php</h1>
<?php foreach(element_children($profile) as $section) {
  print render($profile[$section]);  
}
?>

次に、MYTHEME_theme() 関数を次のように設定します。

function MYTHEME_theme($existing, $type, $theme, $path) {
  return array(
    'profile_section' => array(
      'render element' => 'profile_section',
      'template' => 'templates/profile-section',
    ),
  );
}

最後に、次のように、テンプレート ディレクトリにファイルを設定しprofile-section.tpl.phpます。

<h2>profile-section.tpl.php</h2>
<p>Theming the profile section <strong><php print $profile_section['#type'] ?></strong> with the <strong>standard</strong> profile section template.</strong></p>

これにより、ほとんどの状況で、ユーザープロファイルのセクションにテーマがどのように反応するかについて、必要なすべての動作が得られます。つまり、プロファイル セクションごとに、「profile_section」としてテーマを設定できます。

問題

また、テンプレート ディレクトリにドロップした新しいテンプレート ファイルに基づいて、特定のプロファイル セクションのテーマを処理するテンプレート ファイルをセットアップする機能も必要です。したがって、この例に特有のことですprofile-section.tpl.phpが、ほとんどのプロファイル セクションを処理したい一方で、ファイルをドロップしprofile-section--top-section.tpl.phpてキャッシュをクリアし、テーマでそのファイルを「top_section」プロファイル セクションに使用する機能も必要です。

うまくいかない私の「解決策」

私の問題は、適切なテーマ前処理関数内で theme_hook_suggestions を使用することで解決できることを読みました。したがって、私の場合、MYTHEME_preprocess_profile_section()次のように関数を記述しました。

function MYTHEME_preprocess_profile_section(&$variables) {
  $variables['theme_hook_suggestions'][] = 'profile_section__' . $variables['profile_section']['#type'];
}

次に、profile-section--top-section.tpl.php次のようにファイルを作成しました。

<h2>profile-section--top-section.tpl.php</h2>
<p>Theming the profile section <strong><php print $profile_section['#type'] ?></strong> with the <strong>top-sectoin</strong> profile section template.</strong></p>

これでセットアップは完了です。キャッシュを更新しましたが...

テーマは、私が書いprofile-section.tpl.phpたより具体的なprofile_section__top_section.tpl.phpテンプレートではなく、私の top_section profile_section のテンプレートを引き続き選択します。

このセットアップでテーマの提案を から取得するには、ここから何をする必要がありますか、または何を変更する必要がありますMYTHEME_preprocess_profile_section()か?

4

0 に答える 0