3

I have some share-buttons in a static-block. I control some content on product-level by custom attributes. Is it possible to add a static block in a attribute text area. I tried with {{block type="cms/block" block_id="your_block_id"}} but it's not working?

Thanks

UPDATE:

On this page, look for the text "Famke (en Joost) – Deventer". This content is added at Manage product > product in an Attribute text-area. Below this alinea (in the same text-area i want to add the static-block (with its content, the share buttons). I have to do it like this because of some CSS classes.

  • it's maybe just me, but could you be more specific as to what you tend to achieve? – Julien Lachal Oct 10 '14 at 7:59
  • i updated my question... – Meez Oct 10 '14 at 8:20
2

I've had also the same issue and I found little free extension here http://www.magentocommerce.com/magento-connect/static-blocks-everywhere.html

which allows you to add static block in Description (short too), Agreement and Category description.

If you will take a look at code of this extension you will have clear picture of how to implement it to the custom attributes on product page.

I will update this answer once I will test it with the other combinations.

UPD: That Extension that I mentioned earlier does what it says, but for only three instances, Agreement, Category and Product Descriptions (You can see that in code)

Also you can read here http://forum.azmagento.com/how-to/product-text-area-attribute-with-wysiwyg-src-quot-123-123-media-url-quot-folder-imagejpg-quot-125-125-not-parsed-41450.html

How to parse static block in any text area attribute.

Now I'm able to display my responsive tabs with very flexible way to update and create content - calling specific static blocks.

|improve this answer|||||
1

It's not possible out of the box, but with some coding is possible.
First of all you need to have that attribute as a textarea with WYSIWYG support and allow html on frontend. You can set these values from Catalog->Attributes->Manage Attributes.
Then you need to allow media directives in product attributes.
You can do that from System->Configuration->Catalog->Frontend. Set the value for Allow Dynamic Media URLs in Products and Categories to Yes.

Now you need to change the template processor for the catalog attributes.
By default the textarea attribute values are parsed by the class Mage_Catalog_Model_Template_Filter.
This is defined in the config.xml file of the catalog module.

<config>
    ....
    <global>
        ...
            <catalog>
                ...
                <content>
                    <tempate_filter>catalog/template_filter</tempate_filter><!-- this defines the template processor-->
                </content>
                ...
            </catalog>
        ...
    </global>
    ...
</config>

You have 2 options here.
Option 1.
Rewrite the class Mage_Catalog_Model_Template_Filter and add a new method called blockDirective that you can copy from Mage_Core_Model_Email_Template_Filter.
You can choose this method if you want more control or if you want to add extra modifications to the {{}} directive parsing.
But I wouldn't use that. I would go with ...

Option 2..
Change the template processor. Make the catalog use the same processor that is used for cms blocks and pages because they already have support for {{block}} directives.
An even better idea would be to use the template processor for widgets. This will allow you to use {{widget}} directives in addition to {{block}} directives.
To do that, just create a new module. Let's call it Easylife_Directive.
You can even use one of the modules you have if you don't want to create a new one just for this.
If you create a new module you will need this file. (If you use an existing module you can skip it).

app/etc/modules/Easylife_Directive.xml - the declaration file

<?xml version="1.0"?>
<config>
    <modules>
        <Easylife_Directive>
            <codePool>local</codePool>
            <active>true</active>
            <depends>
                <Mage_Catalog /><!-- Should be loaded after the catalog module -->
            </depends>
        </Easylife_Directive>
    </modules>
</config>

app/code/local/Easylife/Directive/etc/config.xml - the config file where you change the template processor.

<?xml version="1.0"?>
<config>
    <modules>
        <Easylife_Directive>
            <version>1.0.0</version>
        </Easylife_Directive>
    </modules>
    <global>
        <catalog>
            <content>
                <tempate_filter>widget/template_filter</tempate_filter><!-- change the template filter -->
            </content>
        </catalog>
    </global>
</config>

If you want to use one of your existing modules just copy this inside the <global> tag of the config.xml file of the module.

<catalog>
    <content>
        <tempate_filter>widget/template_filter</tempate_filter><!-- change the template filter -->
    </content>
</catalog>
|improve this answer|||||
  • sorry so just for option 2 what are exactly the steps i have to follow. Just for the {{block}} option. Its not totally clear where i have to start. I configured the things by Magento admin... Thanks a lot! – Meez Oct 10 '14 at 13:38
  • @Meez For test purposes, create the 2 files I mentioned and clear the cache. – Marius Oct 10 '14 at 13:39
  • and why you call it Easylife_Directive. Is it just a name..? – Meez Oct 10 '14 at 13:41
  • Step 1) I created app/etc/modules/Easylife_Directive.xml Step 2) What do i have to do next? Which second file i have to create? Thanks – Meez Oct 10 '14 at 13:44
  • app/code/local/Easylife/Directive/etc/config.xml and yes...the Easylife_Directive is just the module name. You can change it to whatever you want, but make sure you change it everywhere. Even in the file names. – Marius Oct 10 '14 at 13:51
1

You can use below code to parse any WYSIWYG editor

Mage::helper('cms')->getPageTemplateProcessor()->filter($this->getContent());

you need to replace $this->getContent() with your attribute's content like Mage::registry('current_product')->getSomeAttributeByCode()

It will work for your requirement!

|improve this answer|||||

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.