私はモジュールを稼働させています。バックエンド側では、いくつかの属性を持つ画像をアップロードでき、画像パスやその他の情報をカスタム テーブルに保存しています。フロントエンドでは、これらの画像をいつ表示する必要があるかをすでに検出できました。表示された製品がカスタム作成されたテーブルで見つかったときに新しいレイアウト ハンドルを追加する Observer を使用しました。次に、そのレイアウト ハンドルで phtml テンプレート ファイルを呼び出し、ここからブロック内の関数を呼び出して、表示する画像を確認するためのすべてのチェックを行います。
私の問題は、これらの画像を表示する方法が見つからないことです。私が見つけたものはすべて、挿入されたphpコードで追加の検証を行うphtmlファイルにイメージタグを追加する方法を参照しています。私の場合、すべてがphtmlファイルの外側のphpコードにあります。
私のphtmlファイルコード:
<div>
<h3><?php $this->showCampaign(); ?></h3>
</div>
今のところ私のブロックコード:
<?php
class Dts_Banners_Block_Front extends Mage_Core_Block_Template {
/**
* Shows a campaign banner according to the current selected product
* Seeks on main banners table to see if it is an image/html/product alone campaign
* Once knows the campaign type search on needed table the needed fields
*/
public function showCampaign() {
//Zend_Debug::dump($this->getLayout()->getUpdate()->getHandles());
$product = Mage::registry('current_product');
$currentProdID = $product->getId();
if (Mage::registry('campaign_data') && Mage::registry('campaign_data')->getId()) {
$currentCampaign = Mage::registry('campaign_data');
} else {
return;
}
// get campaign type and show needed information
switch ($currentCampaign->getbanner_type()) {
case 1: // image
$myImgCollection = Mage::getModel('banners/bannersimg')->getCollection();
$myImgCollection->addfieldtofilter('bannerid',$currentCampaign->getID());
$currentImg = $myImgCollection->getFirstItem();
$currentImgPath = $currentImg->getimg_path();
//{{block type="catalog/product_new" product_id="16" template="catalog/product/view/your_new_page.phtml"}}
break;
case 2: // html
echo "html";
break;
case 3: // plain product url
echo "plain product url";
break;
}
}
}