某システムのアップデート 続き
クエリで商品のカテゴリが流れてるからそれを捕捉してスタイルシートと画像のURLをereg_replace()書き換える事にした。
なんて適当なんだ(ワラ
とはいえスクリプトでまとめてやるっつったって、数十本のスクリプトにそれを書くのは面倒なのでsmartyのポストフィルタでさっくり書き換え。
function smarty_outputfilter_regreplace($source, &$smarty){ if (isset($smarty->_tpl_vars["replace"]) && is_array($smarty->_tpl_vars["replace"])){ foreach ($smarty->_tpl_vars["replace"] as $replacee => $replace){ $source = ereg_replace($replacee, $replace, $source); } } return $source; }
(′∀`) まぁ適当。
使う時は$smarty->assign("replace",array("images"=>"otherImages"))みたいな感じ。