Greetings StackExchange.
I'm not quite sure whether this has been answered before or not. I have done a fair amount of blog / thread searching on this problem/topic.
Is there a way to add a custom attribute to Static Blocks? For example it is possible via. the backend to create a new attribute and add it to a attribute set for products. For categories it has to be done with a small module, a install script and so on.
I have not come across a way of doing this to either of CMS pages or static blocks.
Can somebody help me getting in the right direction?
WHAT I WANT: A dropdown value/attribute for each unique static block, eg "Include, Exclude, Ignore", in the same area as "Status".
1 Answer 1
For this, you need to overwrite this class Mage_Adminhtml_Block_Cms_Block_Edit_Form. This class is used to add fieldsets and fields for cms_block. Take a look on the _prepareForm() method inside it.
If you put this code, just after Title field,
$fieldset->addField('sub_title', 'text', array(
'name' => 'sub_title',
'label' => Mage::helper('cms')->__('Sub Title'),
'title' => Mage::helper('cms')->__('Sub Title'),
'required' => true,
));
you can see your sub-title text field in static blocks. However Do not edit a core file directly. You need to write a custom module that should overwrite this class. Your Module config file should contain this code
File : app/code/local/Namespace/Module/etc/config.xml
<config>
<global>
<blocks>
<adminhtml>
<rewrite>
<cms_block_edit_form>Namespace_Module_Block_Adminhtml_Cms_Block_Edit_Form</cms_block_edit_form>
</rewrite>
</adminhtml>
</blocks>
</global>
</config>
This will allow you to rewrite the class. What you need to do now is define the rewrite class now and in there you need to rewrite _prepareForm(). It should some what look like this.
Location : app/code/local/Namespace/Module/Block/Adminhtml/Cms/Block/Edit/Form.php
<?php
class Namespace_Module_Block_Adminhtml_Cms_Block_Edit_Form extends Mage_Adminhtml_Block_Cms_Block_Edit_Form {
protected function _prepareForm()
{
//put all the code inside parent class here
//then place the below content in appropriate place
$fieldset->addField('sub_title', 'text', array(
'name' => 'sub_title',
'label' => Mage::helper('cms')->__('Sub Title'),
'title' => Mage::helper('cms')->__('Sub Title'),
'required' => true,
));
return parent::_prepareForm();
}
}
Try based on this idea
EDIT
Please note, it will allow you to put new field in cms > block, howver to save this, you need to define model for your module. You have two options. Add a new field to save your new field in Cms> Block table or create your own table and store this value in that field along with the referene to cms>block table. This is out of box and you should implement it your own way.
-
1Thanks alot! I've added a table to the cms_block table.Andreas Therkildsen– Andreas Therkildsen2018年02月14日 12:54:49 +00:00Commented Feb 14, 2018 at 12:54
Explore related questions
See similar questions with these tags.