華麗なるテーマの遷移

Events happening in the community are now at Drupal community events on www.drupal.org.
mihamakei's picture

Hello all.

「DrupalはNode Type別やPage別にテーマを切替えるのは大変だろ?」
このドキュメントはそんな疑問を持つ初心者の方々に捧げます。

グローバル変数 $custom_theme がそれを実現します。
http://api.drupal.org/api/global/custom_theme/6

即席テストコードで検証してみましょう。
* 例えば *
サイトデフォルトテーマ: garland
ユーザー設定テーマ: minnelli
切替え希望テーマ: pushbutton

貴方はコンテンツの作成をします。
本文へPHPcodeフィルタを使いPHPコードを書きましょう。
-ブロックを追加してコードを書いて遊ぶのも良いでしょう。-

<?php
global $user,$custom_theme;

print
variable_get('theme_default','') . '<br />'// サイトデフォルトテーマ
print $user->theme . '<br />'// ユーザー設定テーマ
$custom_theme = 'pushbutton'// 切替え実行
print $custom_theme .'<br />'// 切替えたテーマ
?>

テストはいかがだったでしょうか?
init_theme()が呼ばれる度に$custom_themeを参照します。
http://api.drupal.org/api/function/init_theme/6

これを使った便利なモジュールもリリースされています。

Nodeごと(ページごと)にテーマを設定する Node theme
http://drupal.org/project/node_theme

Node Type ごとにテーマを設定する Node type theme
http://drupal.org/project/nodetypetheme

どちらもhook_init()で処理されています。

最後に この文章が貴方の人生にとって有益なものである事を願っています。

mihamakei@煙樹ヶ浜に生息中

日本 コミュニティ: Drupal Japan User Group

Group organizers

Group categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: