5

In Magento 1, if you wanted to transform an arbitrary block of text, the same as the body of a CMS page or block might be changed, you could use the following model class

Mage::getModel('cms/template');

This object was also available via the CMS data helper's getBlockTemplateProcessor method.

Mage::helper('cms')->getBlockTemplateProcessor();

In Magento 2, there is no CMS data helper object. There is also no CMS template object.

In Magento 2, if I want to transform an arbitrary string as through it were a CMS page or CMS block, how would I do that?

1 Answer 1

6

if I understand you correctly, you can do this with the

Magento\Cms\Model\Template\FilterProvider

if you want to "filter" a string with cms "objects" it should be working like this:

return $this->filterProvider->getBlockFilter()
        ->setStoreId($this->storeManager->getStore()->getId())
        ->filter($yourString);

hope I understood your question right :X

3
  • Yup, that's the class I was looking for. Thank you for saving me the code glopping! :) Commented Feb 10, 2016 at 21:26
  • Wow, done without a single static method. Commented Feb 11, 2016 at 4:05
  • I have used like below in m1. $filter = Mage::getModel('cms/template_filter'); $filter->setVariables($array); How to use this in m2? Commented Nov 2, 2018 at 8:41

Your Answer

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

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