Wayfinderの改造 - テンプレートの追加  【解決済み】

質問全般・改善要望
返信する
Ryo
メンバー
メンバー
記事: 24
登録日時: 2009年8月25日(火) 13:19

Wayfinderの改造 - テンプレートの追加  【解決済み】

投稿記事 by Ryo »

こんにちわ。

Wayfinderの事で教えてください。

リンク属性にrel="category"とすることでcategoryFoldersTplが適応されますよね。
これを任意の階層でrel="sub_category"とすることでsub_categoryFoldersTplを適応させたいのですが、可能でしょうか?

よろしくお願いします。
sama55
メンバー
メンバー
記事: 816
登録日時: 2009年8月03日(月) 08:16

Re: Wayfinderの改造 - テンプレートの追加

投稿記事 by sama55 »

Ryo さんが書きました:リンク属性にrel="category"とすることでcategoryFoldersTplが適応されますよね。
これを任意の階層でrel="sub_category"とすることでsub_categoryFoldersTplを適応させたいのですが、可能でしょうか?
フォルダに適用するテンプレートが有限なら、wayfinder.inc.phpのL160近辺のコードの複製で対処できそうな気がしますが、いかがでしょ?
(未検証なので自分で検証してください)

【変更前】

コード: 全て選択

        } elseif ($resource['isfolder'] && ($resource['template']=="0" || is_numeric(strpos($resource['link_attributes'],'rel="category"'))) && $this->_templates['categoryFoldersTpl'] && ($resource['level'] < $this->_config['level'] || $this->_config['level'] == 0)) {
            $usedTemplate = 'categoryFoldersTpl';
【変更後】

コード: 全て選択

        } elseif ($resource['isfolder'] && ($resource['template']=="0" || is_numeric(strpos($resource['link_attributes'],'rel="category"'))) && $this->_templates['categoryFoldersTpl'] && ($resource['level'] < $this->_config['level'] || $this->_config['level'] == 0)) {
            $usedTemplate = 'categoryFoldersTpl';
        } elseif ($resource['isfolder'] && ($resource['template']=="0" || is_numeric(strpos($resource['link_attributes'],'rel="sub_category"'))) && $this->_templates['categoryFoldersTpl'] && ($resource['level'] < $this->_config['level'] || $this->_config['level'] == 0)) {
            $usedTemplate = 'sub_categoryFoldersTpl';
別な対処法として、is_numeric(strpos($resource['link_attributes'],'rel="category"')) の判断文と、$usedTemplate = 'categoryFoldersTpl'のテンプレート名の設定を動的に処理するように改造すれば、テンプレートが増える度にソースを書き換える手間が省けそうですが、strposによる文字列照合をアバウト(例えば"rel="だけとか)にしてしまうと、リンク属性を利用する他の部品の影響で、Wayfinderが正しく動かなくなる可能性が高まりそうです。
Ryo
メンバー
メンバー
記事: 24
登録日時: 2009年8月25日(火) 13:19

Re: Wayfinderの改造 - テンプレートの追加

投稿記事 by Ryo »

sama55さま
アドバイスありがとうございます。

追加したいテンプレートは一つだけだったので、160行目のコード複製をやってみましたが、動作しないです :|

試しに、適応される事がはっきりしている、160行目付近のrowTplやouterTplをsub_categoryFoldersTplに変更してみると、該当部分のhtmlが出力されなくなります。
他の部分にテンプレート名の設定か、適応順序の設定などがあるのかな、と思ってコードを眺めてみましたが、わかりませんでした。
sama55
メンバー
メンバー
記事: 816
登録日時: 2009年8月03日(月) 08:16

Re: Wayfinderの改造 - テンプレートの追加

投稿記事 by sama55 »

Ryo さんが書きました:追加したいテンプレートは一つだけだったので、160行目のコード複製をやってみましたが、動作しないです :|
やはりちゃんとテストしないとダメですね。 I'm sorry... :cry:
私の環境では下の変更で動いたので試してみてください。

【Wayfinderスニペットの改造】 ※1行追加

コード: 全て選択

//get user templates
$wf->_templates = array(
	'outerTpl' => isset($outerTpl) ? $outerTpl : '',
	'rowTpl' => isset($rowTpl) ? $rowTpl : '',
	'parentRowTpl' => isset($parentRowTpl) ? $parentRowTpl : '',
	'parentRowHereTpl' => isset($parentRowHereTpl) ? $parentRowHereTpl : '',
	'hereTpl' => isset($hereTpl) ? $hereTpl : '',
	'innerTpl' => isset($innerTpl) ? $innerTpl : '',
	'innerRowTpl' => isset($innerRowTpl) ? $innerRowTpl : '',
	'innerHereTpl' => isset($innerHereTpl) ? $innerHereTpl : '',
	'activeParentRowTpl' => isset($activeParentRowTpl) ? $activeParentRowTpl : '',
	'categoryFoldersTpl' => isset($categoryFoldersTpl) ? $categoryFoldersTpl : '',
	'subcategoryFoldersTpl' => isset($subcategoryFoldersTpl) ? $subcategoryFoldersTpl : '', //★ add line ★
	'startItemTpl' => isset($startItemTpl) ? $startItemTpl : '',
);
【Wayfinder.inc.phpの改造】 ※3行追加(L160近辺)

コード: 全て選択

        } elseif ($resource['isfolder'] && ($resource['template']=="0" || is_numeric(strpos($resource['link_attributes'],'rel="subcategory"'))) && $this->_templates['subcategoryFoldersTpl'] && ($resource['level'] < $this->_config['level'] || $this->_config['level'] == 0)) {
            $usedTemplate = 'subcategoryFoldersTpl';
【呼び出し例】
[[Wayfinder? &startId=`0` &categoryFoldersTpl=`FolderTpl` &subcategoryFoldersTpl=`subFolderTpl`]]

【リソース(リンク属性)の設定】
FolderTplを適用する場合: rel="category"
subFolderTplを適用する場合: rel="subcategory"

【確認したこと】
FolderTplとsubFolderTplチャンクを作り、双方のチャンクに違う文字列を埋め、正しく呼び分けられることを確認。
Ryo
メンバー
メンバー
記事: 24
登録日時: 2009年8月25日(火) 13:19

Re: Wayfinderの改造 - テンプレートの追加

投稿記事 by Ryo »

sama55さま

できました!!!
wayfinderってスニペットもあったのですね・・・。スニペットコールで呼び出してるんだから当然か(汗

ありがとうございました。
返信する