I am creating a playground external PHP script in Magento 2, trying to output a static block. It works but the block output always has template path hints -- how can I get rid of the red? Template hints are disabled everywhere in config and Mage mode is set to "developer".

Block class


namespace Ont\Ax\Block\Aif;
use Magento\Framework\View\Element\Template;
class Agreements extends Template {
    function __construct(Template\Context $context) {
    public function foo() {
        return "bar";

Block template


<h2>Foo? <?php echo $this->foo() ?></h2>

Test file


use Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';
$params = $_SERVER;
$bootstrap = Bootstrap::create(BP, $params);
$obj = $bootstrap->getObjectManager();
$state = $obj->get('Magento\Framework\App\State');
/* @var Magento\Store\Model\StoreManagerInterface $storeManager */
$storeManager = $obj->create("\Magento\Store\Model\StoreManagerInterface");
/* @var \Magento\Framework\View\LayoutInterface $layout */
$layout = $obj->create("\Magento\Framework\View\LayoutInterface");
$block = $layout->createBlock("Ont\Ax\Block\Aif\Agreements");
echo $block->toHtml();


Screenshot of result


Try adding the below lines of code after $state->setAreaCode('frontend');

$configLoader = $obj->get('Magento\Framework\ObjectManager\ConfigLoaderInterface');

This worked for me. Reference: Magento2 - Command-Line - Sending Email Using Block Templates - Error: Missing required argument $debugHintsPath

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.