0

I am using additional.phtml to add some custom extra information to 1 best-of-product of mine - like images, videos or text and I do this by hardcoded adding of markup-code directly to the additional.phtml-file in a separate sub-package - ouch, I know. Now I want to extend this functionality to more products and I am wondering, if this isn't doable via the dashboard directly to also keep it managable more easily.

Therefore I added 3 CMS static block in the dashboard and would like to integrate block_1 into product_1's page and block_2 into product_2's page ... and I use this in the additional.phtml-file of my theme

<? echo $this->getLayout()->createBlock('cms/block')->setBlockId('block_1')->toHTML(); ?>

But I have no clue on how to now define, that block_1 shall be shown on product_1 etc. Where would I need to do that? In the dashboard?


UPDATED

Based on the given hint of Amit, I added a new attribute and some cms-blocks and I am doing this now in my additional.phtml-file

<?php
$_helper = $this->helper('catalog/output');
$_product = $this->getProduct();
if (!$_category = Mage::registry('current_category')) {
    $_product = Mage::getSingleton( 'catalog/product' )->load( $_product->getId() );
}
$_product->getSetCms(); 
echo $this->getLayout()->createBlock('cms/block')->setBlockId($_product)->toHTML(); ?>

But I do get a: Fatal error: Call to a member function getId() on a non-object What am I doing wrong here?

  • Ideall to create an product attribute and then assign the block ids to product attribute value – Amit Bera Apr 17 '15 at 9:41
  • Thanks for that idea. So I would create a new attribute and assign a special value to it > getthisvalue in my additional.phtml-file > and use it like this <? echo $this->getLayout()->createBlock('cms/block')->setBlockId($value_ofattribute)->toHTML(); ?> – Daiaiai Apr 17 '15 at 10:45
  • Do you have product in $this? Maybe get it the same way as category? $_product = Mage::registry('current_product') – zhartaunik Apr 17 '15 at 12:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.