2

this is a beginner question for sure - so go easy on me?:

I'm calling some extension output using code such as this:

{{block type="downloads/link" id=123 title="Description"}}

This code works, when its in a static block, or a CMS page.

However, when I enter it into a category description panel (along with some other HTML/CSS), it doesn't work.. Magento will just output the code to screen. I'm guessing that Magento doesn't process the code within a category description panel, the same way it does in a static block.

This is annoying, as I now need to create 20 or static blocks, to show my block results in different places.

Is there someway to use a {{block}} call in other pages, perhaps wraping in other code? Using an extension?

I feel as though this question might be the answer, but the solution there doesn't really help me as it requires embedding even more code: how to call block in short description on product page?

Thanks.

4

You can use custom layout XML to get blocks into your category, product and CMS pages:

Categories
1. In the admin area navigate to Catalog > Manage Categories and select the category you want to update
2. Click the "Custom design" tab and enter the following into the "Custom Layout Update" text area:

<reference name="content">
    <block type="downloads/link" name="downloads.link">
        <action method="setId"><id>123</id></action>
        <action method="setTitle"><description>Description</description></action>
    </block>
</reference>

3. Save the category and flush the necessary caches

Products
1. Navigate to Catalog > Manage Products and select the product you want to add the block to
2. Click the "Design" tab and enter the XML above into the "Custom Layout Update" text area

You will be fairly limited in where you can place the block - only blocks of type "core/text_list" (like the "content" block) will output all their child blocks. Others would need to call the child block using $this->getChildHtml('downloads.link');

If you want to add the block to multiple categories or products or want better placement options you may be better to output the block using the category or product PHTML file. You could dynamically pull in the download link ID and Title by creating a custom product or category attribute. Below is a really basic example of how you could do this. Keep in mind it's not best practice to put this kind of logic in a PHTML file.

<?php echo $this->getLayout()->createBlock('downloads/link', 'downloads.link', array(
    'id'    => $this->getDownloadsId(),
    'title' => $_product->getName() . ' downloads'
))->toHtml()?>

Hope these ideas help.

| improve this answer | |
  • actually, I tried this now (in the category page) and it doesn't work. Do I need to do something else? – egg Feb 3 '15 at 11:05
  • Just updated my answer, I think I forgot the ->toHtml() method at the end – jharrison.au Feb 3 '15 at 11:09
  • OK thanks. However, I only tried adding the reference section to the layout update ... on save and refresh, nothing shows. – egg Feb 3 '15 at 11:30
  • 1
    did you flush your cache? Also check system.log and exception.log for any problems. – jharrison.au Feb 3 '15 at 11:37
  • 1
    Let us continue this discussion in chat. – jharrison.au Feb 4 '15 at 8:45
1

This is a common problem I face a lot. A request is made where the client would like to place custom blocks on Category pages for example. This needs to be dynamic for each category.

What I tend to do is:

1) Create a very simple module so that I can have a custom block 2) Via XML add the block to the layout.xml file for the theme and the position I want. 3) In the block load the cms block that is cms-block-category-cat-id where cat-id is the numerical ID of the category 4) Block phtml then will load the contents of the cms block and output onto the screen

There is more code than what you would like but it does provide control over the content that is being presented to the visitors.

| improve this answer | |
  • thanks. This gives me some ideas to try out... never made a module before - I guess I should learn! – egg Feb 2 '15 at 7:09

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.