i had created a new module on Magento 2. It have:

setup -> UpgradeData.php :

    public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
        /**@var \Magento\Cms\Model\Page $page */
        if (version_compare($context->getVersion(), '1.1') < 0) {
            $page = $this->_pageFactory->create();
            $page->setTitle('Voucher CMS')
                ->setContent('{{block class="Cincuenta\\Voucher\\Block\\Product\\View\\Extra" block_id="voucher-cms" template="Cincuenta_Voucher::voucher/voucher.phtml"}}


It creates well my new CMS with the content.

I had a phtml on view -> frontend -> templates -> voucher -> voucher.phtml:

<h1> Test Voucher</h1>

and Block - Product -View - Extra.php:


namespace Cincuenta\Voucher\Block\Product\View;

class Extra extends \Magento\Catalog\Block\Product\View


Code on my CMS:

{{block class="Cincuenta\\Voucher\\Block\\Product\\View\\Extra" block_id="voucher-cms" template="Cincuenta_Voucher::voucher/voucher.phtml"}}

But when i try to see my H1 in my CMS, it don't give me nothing, but a few times gives me an error that i was calling a wrong block.

  • what are you try to say? – Rakesh Jesadiya May 13 '16 at 11:49
  • The phtml isn't showed in my CMS page – ntzz May 13 '16 at 11:51

Your code looks fine. However, you said that your .phtml file is

view -> templates -> voucher -> voucher.phtml

Ideally, it should be here:

view -> frontend -> templates -> voucher -> voucher.phtml

  • Sorry , i forgot the frontend, but it was there created. So, why i couldn't see nothing? – ntzz May 17 '16 at 7:58
  • Dunno how but it get solved with the same code today just changing my block_id to 'vouchercms' instead of 'voucher-cms' . Dunno what was the problem, but thanks. – ntzz May 17 '16 at 8:14

First run command.

php bin/magento setup:upgrade

You have to write below code inside cms page,

{{block class="Cincuenta\Voucher\Block\Product\View\Extra" template="Cincuenta_Voucher::voucher/voucher.phtml.phtml"}}

Remove var folder and check again.

  • If you see, i had the same code inserted in my content of CMS in my UpgradeData.php . I run the command to update my changes all times so that is not the problem. – ntzz May 13 '16 at 12:06
  • Have you tried using above code in your cms page? – Rakesh Jesadiya May 13 '16 at 12:07
  • what you mean? Use code on my CMS content page? – ntzz May 13 '16 at 12:08
  • yes you have to define in cms content page to display inside your cms page – Rakesh Jesadiya May 13 '16 at 12:11
  • I had already this line of code on my content page. See my UpgradeData.php and my setContent() – ntzz May 13 '16 at 12:16

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.