定义magento模板路径

时间:2016-03-04 09:00:49

标签: magento

我正在以编程方式在 Magento管理控制器中加载一个块,就像这样

`$block = $this->getLayout()->createBlock('core/text')->setText('<script type="text/javascript" ></script>');`

现在,我想使用setTemplate方法而不是setText。我在这个目录中创建了一个temlplate文件design / adminhtml / default / default / product / productcrop.phtml

我应该如何加载它,即setTemplate方法中的参数是什么?

我试过这种方式: - &gt; setTemplate(&#39; adminhtml / product_productcrop.phtml&#39;)。但它似乎没有起作用。

整个控制器代码是:

<?php 
class Homeliv_Leadsadmin_Adminhtml_ProductController extends Mage_Adminhtml_Controller_Action {
    public function indexAction() {
        $this->loadLayout()->_setActiveMenu('leadsadmin/product');
        $this->_addContent($this->getLayout()->createBlock('leadsadmin/adminhtml_product'));
        $this->renderLayout();
    }

    public function editAction() {

        $product_id = $this->getRequest()->getParam('id');
        $full_product = Mage::getModel('catalog/product')->load($product_id);
        $productMediaConfig = Mage::getModel('catalog/product_media_config');
        //$baseImageUrl = $productMediaConfig->getMediaUrl($full_product->getImage());
        //$thumbImageUrl = $productMediaConfig->getMediaUrl($full_product->getThumbnail());
        $smallImage = $productMediaConfig->getMediaUrl($full_product->getSmallImage());


        $this->loadLayout();
        //$this->_title($this->__("Product"));   
       /* $block = $this->getLayout()->createBlock('core/text')->setText('<script type="text/javascript" src="'.Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB).'media/leadsadmin/product_crop.js'.'"></script>');
        $this->_addJs($block);

        $this->_addLeft($this->getLayout()
        ->createBlock('core/text')
         ->setText('<h1>Image</h1><img src="'.$smallImage.'"/>'));



        $block = $this->getLayout()
        ->createBlock('core/text')
        ->setText('<h1>Main Block</h1>');           
        $this->_addContent($block);*/


        $block = $this->getLayout()->createBlock('core/template')-> setTemplate('product/productcrop.phtml')->toHtml();
        $this->_addContent($block);

        //$this->getLayout()->createBlock('leadsadmin/adminhtml_product')->setTemplate('product/productcrop.phtml')->toHtml();
        //$this->getLayout()->createBlock('core/text')->setText('<div>ssxsxsx</div>');
        $this->renderLayout();

        //var_dump(Mage::getSingleton('core/layout')->getUpdate()->getHandles());
        //die();

        //$this->loadLayout()->_setActiveMenu('leadsadmin/product');
        //$this->_addContent($this->getLayout()->createBlock('leadsadmin/adminhtml_product'));
        //$this->renderLayout();
    }


}

1 个答案:

答案 0 :(得分:0)

您拥有的模板。您的模板路径将是设置模板product/productcrop.phtml

 $block = $this->getLayout()
    ->createBlock('core/template')
    ->setTemplate('product/productcrop.phtml');

$this->getLayout()->getBlock('content')->append($block);