layout - Magento _prepareLayout() called 5 times to many -


** new edit **

so i'm trying this.

i want add new form elements generated module on product view of following url

http://magento.example.com/catalog/product/view/id/46 

ultimately these elements determined show related table in module

i expected if extended mage_catalog_block_product_view in module shown below able create block in product form contain such form fields, if in related table in module

so created test.phtml file in

 app/design/frontend/default/default/templates/<module>/test.phtml 

then can see in view.php file described bellow built block , displayed in product view.

it did appear 5 times many. answers below normal answers question why shows 5 times leaves question proper way proceecd since plan not going work

** end new edit **

in module call _preparelayout() , 5 times when pull page

here's code in

/app/code/local/namespace/module/product/veiw.php class <namespace>_<module>_block_product_view extends mage_catalog_block_product_view {     protected function _tohtml() {         return parent::_tohtml();     }      public function _preparelayout() {         $block = $this->getlayout()->createblock(             'mage_core_block_template',             'my_block_name_here',             array('template' => '<module>/test.phtml')         );         if ($block){             $this->getlayout()->getblock('content')->insert($block)->tohtml();         }else{             echo "no block";         }             return parent::_preparelayout();     } } 

note: noticed takes away price availability qty , add cart button. problem

edit first want thank answers. second want give more context

the reason choosing in module don't want block show on every product . have table of i'll call custom options containing properties of product sort of hair color height weight etc , depending on set of properties attached product (if any) depend on html content show on page. in 1 case drop down menu , in case may input box. other important piece must setup can give end result out module can installed , not worrry won't show if upgrades there magento

that said still make sense in xml file ?

i took @ stock magento install of ce 1.4.1, , unmodified _preparelayout method called six times when loading url

http://magento.example.com/catalog/product/view/id/46 

that's because class instantiated 6 times. that's correct behavior.

as vanishing element, can'y sure, override _preparelayout doesn't appear either

  1. do same things mage_catalog_block_product_view::_preparelayout

  2. call parent::_preparelayout();

when override class in magento you're replacing existing class own. if change method, you're responsible old code being run.

it's not clear you're trying accomplish here. should consider breaking problem down smaller problems, , posting 1 (or more) "i tried x, expected y, , got z" type questions. written no one's going able answer question.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -