0

I have created one CMS static block.

I want to know that can I change its content by code (programmatically).

Is there any way to do it?

0

Use this

Load by block id:

Mage::getModel('cms/block')->load($id)
  ->setData('content', 'SET CONTENT HERE')
  ->save();

Load By identifier:

Mage::getModel('cms/block')
  ->getCollection()
  ->addFieldToFilter('identifier', 'block_identifier')
  ->load()
  ->setData('content', 'Example content')
  ->save();
  • can i use this code in custom module – inrsaurabh Oct 24 '17 at 8:11
  • @SaurabhRanjan Yes, you can use it – Anil Suthar Oct 24 '17 at 17:22
2

Using below code you can load cms block using identifier

 Mage::getModel('cms/block')->load('{BLOCK_IDENTIFIER}')->setContent('your-content')->save();

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.