[EC-CUBE]Smartyのデバッグを表示させる

概要

EC-CUBEをさわる以前にもSmartyは使ったことがあって、そのときに開発には必須ともいえる{debug}*1 を多用していたのですが、どういうわけかEC-CUBEでは{debag}が使えないので不便を感じておりましたが…今日ようやく使えるようになりましたので、記事にします。

ヒント、というよりは答えそのものですが、フォーラムのこちらを見てやってみたらできたので、具体的な方法を書いておきます。

EC-CUBEでSmartyのdebagを表示させる方法

/data/modules/Smarty/libs/debug.tplを開いてください。
ここでisset関数が3箇所使われている箇所がありますが、Smartyの中ではそのままPHP関数を使うことができません*2
よくわかりませんが、default_modifiersを無効にするsmarty:nodefaults 修飾子をつけることでisset関数が使えるようになるので、3箇所のissetを以下のように修正しましょう。

EC-CUBE 2.3.3
/data/modules/Smarty/libs/debug.tpl
7行目付近

{if isset($_smarty_debug_output|smarty:nodefaults) and $_smarty_debug_output eq "html"}

12行目付近

		<tr bgcolor={if %templates.index% is even}#eeeeee{else}#fafafa{/if}><td colspan=2><tt>{section name=indent loop=$_debug_tpls[templates].depth}&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;{/section}<font color={if $_debug_tpls&#91;templates&#93;.type eq "template"}brown{elseif $_debug_tpls&#91;templates&#93;.type eq "insert"}black{else}green{/if}>{$_debug_tpls[templates].filename|escape:html}</font>{if isset($_debug_tpls[templates].exec_time|smarty:nodefaults)} <font size=-1><i>({$_debug_tpls[templates].exec_time|string_format:"%.5f"}){if %templates.index% eq 0} (total){/if}</i></font>{/if}</tt></td></tr>

44行目付近

		_smarty_console.document.write("<tr bgcolor={if %templates.index% is even}#eeeeee{else}#fafafa{/if}><td colspan=2><tt>{section name=indent loop=$_debug_tpls[templates].depth}&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;{/section}<font color={if $_debug_tpls&#91;templates&#93;.type eq "template"}brown{elseif $_debug_tpls&#91;templates&#93;.type eq "insert"}black{else}green{/if}>{$_debug_tpls[templates].filename|escape:html|escape:javascript}</font>{if isset($_debug_tpls[templates].exec_time|smarty:nodefaults)} <font size=-1><i>({$_debug_tpls[templates].exec_time|string_format:"%.5f"}){if %templates.index% eq 0} (total){/if}</i></font>{/if}</tt></td></tr>");

これでめでたく{debug}が使えるようになるはずです。
{debug}が使えるのと使えないのとじゃ開発効率が雲泥の差ですよね。もっと早く気付くことができたら…^^;

フォーラムの某ゲスト様には超感謝&リスペクトです。
それにしても、こんな素晴らしいTIPSを埋もれさせたままではいけないような気がするのは僕だけ?それとも皆さんは当然のように知っいることなのかなぁ?

  1. デバッギングコンソールを表示させる組み込みの関数。何のことやらわからない方はこの辺を参照してください。こことかここ []
  2. ここにはif文の中では使えるようなことが書いてあるけど、Smartyのバージョンによって違うのかな?それともプラグインが絡んでいるのだろうか?ともあれdebug.tplを見るとif文の中にそのままisset関数を書いているからITProに書かれていることは間違ってなくて、EC-CUBE側の問題なのかも。 []
スポンサーリンク
336x280_1
336x280_1

シェアする

  • このエントリーをはてなブックマークに追加

フォローする

スポンサーリンク
336x280_1