0

I created a block and a template. I call the template in a CMS site.

Block:

\app\code\Fekete\Newsletter2Go\Block\Form.php

<?php
namespace Fekete\Newsletter2Go\Block;

/**
 * Dashboard Customer Info
 *
 * @api
 * @since 100.0.2
 */
class Form extends \Magento\Framework\View\Element\Template
{
    public $helper;
    /**
     * Constructor
     *
     * @param \Fekete\Newsletter2Go\Helper\Data $helperData
     * @param \Magento\Framework\View\Element\Template\Context  $context
     * @param array $data
     */
    public function __construct(
        \Fekete\Newsletter2Go\Helper\Data $helperData
        ,\Magento\Framework\View\Element\Template\Context $context
        ,array $data = []
    ) {
        $this->helper = $helperData;
        parent::__construct($context, $data);
    }

    /**
     * @return string
     */
    public function test()
    {
        return __('Hello Developer! This how to get the storename: %1 and this is the way to build a url: %2', $this->_storeManager->getStore()->getName(), $this->getUrl('contacts'));
    }

}

Template:

\app\code\Fekete\Newsletter2Go\view\frontend\templates\partials\subscribe\form.phtml

<?php
/**
 * @var \Fekete\Newsletter2Go\Block\Form $block
 */ 
    echo $block->test();
?>

I call the template in the CMS page like this:

{{block class="Magento\Framework\View\Element\Template" template="Fekete_Newsletter2Go::form.phtml"}}

Result:

Error filtering template: Invalid method Magento\Framework\View\Element\Template::test

0

I figured it out. The error is in the call...

{{block class="Magento\Framework\View\Element\Template" template="Fekete_Newsletter2Go::form.phtml"}}

It should be:

{{block class="Fekete\Newsletter2Go\Block\Form" template="Fekete_Newsletter2Go::partials/subscribe/form.phtml"}}

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.