1

we add blocks to cms/blocks and pages using this convention

{{block type="cms/block" block_id="my_block1"}}
{{widget type="cms/widget_block" template="cms/widget/static_block/default.phtml" block_id="my_block2"}}

Now recently I had to specificall set the CSS styling to my_block1 (or my_block2 for that matter) when I saw that these blocks all have the same CSS CLASS widget widget-static-block. I was hoping to see something widget widget-static-block my_block1

My question: Now how can we add the block ID to the class? And would this not be a good idea to add to Magento core?

And as a side question: what exactly is the difference between the two cms/block calls? (1 widget and 1 block both under cms)

So the result would be something like widget widget-static-block my_block1 or cms_block my_block1

ps. I do understand there may be some caveats - because you might not want to always expose the exact block ID in your HTML. But I can imagine that for instance the name="" or as="" statement could in that case function as the name and it can be passed via the cms/block call and added as a CLASS element.

1 Answer 1

2

You can copy the template cms/widget/static_block/default.phtml to your theme and replace the original content

<div class="widget widget-static-block"><?php echo $this->getText(); ?></div>

with

<div class="widget widget-static-block <?php echo $this->getBlockId();?>"><?php echo $this->getText(); ?></div>

As for your side question, the only difference is that you can specify a template when using the widget approach. So you can have some kind of markup around the block text. Just like the template used in your example.

3
  • And would this be an idea for Magento core?
    – snh_nl
    Jul 22, 2015 at 20:18
  • I'm not in a position to say that.
    – Marius
    Jul 22, 2015 at 20:37
  • just oto be clear this is for cms/widget_block only?
    – snh_nl
    Jan 31, 2017 at 21:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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