Get Free Audit

Custom Variables and Filters in Static Blocks in Magento 2

Aug 22, 2016

4493 Oleg Semenov

Custom Variables and Filters in Static Blocks in Magento 2

In the following article I’d like to share my experience of creating custom variables and filters in static blocks, including further configuration.

This topic seems rather interesting to me, and I think it would be very significant for developers. I was confused when I faced a similar task and spent a lot of time trying to find solution, but finally found it in Magento 2 code.

So let’s begin:

At first we have to create module, for example Belvg_CustomStaticBlockFilters. It will consist  of the following files:

  • Block/Block.php — our modified block, that will be used on CMS pages or anywhere else.
  • etc/module.xml — well-known module file.
  • Helper/Data.php — additional code (if required)
  • Model/Template/Filter.php — our magic filter :-)
magento custom development

Magento Custom Development

Take your online store to the next level with BelVG Magento Custom Development

Visit the page

Block.php code example:


Filters.php code example:

Andrey_Dubina
Partner With Us Let's discuss how to grow your business. Get a Free Quote.
Talk to Andrey


Right after Class and Function description let’s start their implementation:

Example of use in layout.xml:


Example of use in code:


dataFormat filter example of use:


Custom Variables and Filters in Static Blocks in Magento 2

Eventually we end up with the following page.

Custom Variables and Filters in Static Blocks in Magento 1

I do really hope this article will help you with module development in future. Have a nice day, friends!

Magento support

Magento Support

Take your online store to the next level with BelVG Magento Support

Visit the page
Andrey Dubina
Partner With Us Looking for a partner to grow your business? We are the right company to bring your webstore to success. Talk to Andrey

Post a new comment

BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *