I've managed to successfully add a new image upload field to the CMS edit form. I have it saving to the media folder, etc, so everything works in that area, but I'm having trouble conceptualized how to display this image on the CMS page.

I'm assuming this would use Magento's DataProvider class? Would I need a block class that somehow pulled in the getData() method?

(Forgive me if this doesn't make sense, I'm still learning the backend)

Any clues/nudges would be appreciated.

  • check it will help you : magento.stackexchange.com/questions/167131/… – Nikunj Vadariya May 11 '18 at 13:57
  • Can you please clarify where you want to display that image ? where exactly in cms page (content, menu, grid ...) ? – PЯINCƏ May 11 '18 at 13:57
  • @NikunjVadariya -- that post actually helped me get to where I am, but doesn't address actually rendering the content. Thanks, though! – brackfost May 11 '18 at 14:33
  • @Prince : I know how to manipulate layout files, etc, so that information shouldn't be relevant. Just going to toss a custom block in a referenceContainer for "content" -- but I need to know what the block class should be, and what kind of code I need in that block, etc. (Thanks for the comment) – brackfost May 11 '18 at 14:37

I figured out my issue.
In my cms_page_view.xml, I ended up adding a block with the class of [Vendor]\[Module]\Block\Display that extends \Magento\Cms\Block\Page, with a _toHtml() function inside that returns $html = $this->_filterProvider->getPageFilter()->filter($this->getPage()->getMasthead());

The key for me was getMasthead(). I didn't know that certain methods worked magically in Magento-- Masthead was the name of my field, so getMasthead() worked.

This might all be too specific to my scenario to help anyone, but please let me know if you've had issues following any of the tutorials/posts about adding custom CMS fields and I might be able to help you now.

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.