テンプレート内に置換文字(例えば$$)を設定しておくと
その文字にページ名を置換してくれる機能がほしい
例えば
ページ名がほげほげでテンプレートを使用して作成する場合
- テンプレート
#lookup(Yahoo,検索,$$) [[Yahoo:$$]] http://aaa.bbb.com/ccc/$$↓- 新ページ、ほげほげ
#lookup(Yahoo,検索,ほげほげ) [[Yahoo:ほげほげ]] http://aaa.bbb.com/ccc/ほげほげとか色々と展開が出来ると思うのですが、どうですか?
pukiwiki.ini.php
$str_rules = array( 'now\?' => format_date(UTIME), 'date\?' => get_date($date_format), 'time\?' => get_date($time_format), // '&now;' => format_date(UTIME), // '&date;' => get_date($date_format), // '&time;' => get_date($time_format), + '&page;' => $page, );
これで &page; と記述すると、書き込み時にそのページ名に置換される。れいみぃ・ヘルプ
pukiwiki.ini.php +///////////////////////////////////////////////// +// ユーザ定義ルール(テンプレート展開時に置換する) +$template_rules = array( + '$$' => $post['page']; // 駄目 ? :-) +); edit.inc.php if (array_key_exists('template_page',$post) and is_page($post['template_page'])) { $post['msg'] = join('',get_source($post['template_page'])); + $post['msg'] = make_template_rules($post['msg']); } html.php +// ユーザ定義ルール(テンプレート展開時に置換する) +function make_template_rules($str) +{ + global $template_rules; + + foreach($template_rules as $rule => $replace) + { + $rule = preg_quote($rule,'/'); + $str = preg_replace("/$rule/",$replace,$str); + } + return $str; +}
pukiwiki.ini.php +///////////////////////////////////////////////// +// ユーザ定義ルール(テンプレート展開時に置換する) +$template_rules = array( + '$$' => $post['page'], +);
func.php/auto_template() $body = str_replace("\$$i",$matches[$i],$body); ←これ
$auto_template_func = 1; $auto_template_rules = array( '(.+)' => ':template' );
'&page;' => substr($page,strrpos('/'.$page,'/')), '&fpage;' => $page,
階層化されたページ「hogehoge/hoge」で&page;は「hoge」を、&fpage;は「hogehoge/hoge」に置換する。
$auto_template_rules = array( '((.+)\/([^\/]+))' => '\2/template', // (1) '((.+)\/([^\/]+))' => 'template', // (2) '(()(.+))' => 'template' // (3) );と書いておくと、以下のような順序でテンプレートを探すようにしました。
(1) : $1=hoge/fuga $2=hoge $3=fuga template=[[hoge/template]] (2) : $1=hoge/fuga $2=hoge $3=fuga template=[[template]] (3) : $1=fuga $2='' $3=fuga template=[[template]]
// コメントを使う例 $auto_template_rules = array( '((.+)\/([^\/]+))(?# 特定階層のみのテンプレート)' => '\2/template', '((.+)\/([^\/]+))(?# 汎用テンプレート)' => 'template', '(()(.+))' => 'template' ); // 空文字列にヒットさせる例 $auto_template_rules = array( '((.+)\/([^\/]+)).?' => '\2/template', '((.+)\/([^\/]+)).?.?' => 'template', '(()(.+))' => 'template' );