I've followed a tutorial found here: https://webkul.com/blog/add-custom-image-attribute-category-magento-2/
With a slight modification which can be found in the InstallData, where I specified 'visible_on_front' :
<?php
namespace Vendor\Module\Setup;
use \Magento\Framework\Setup\ModuleContextInterface;
use \Magento\Framework\Setup\ModuleDataSetupInterface;
use \Magento\Framework\Setup\InstallDataInterface;
use \Magento\Eav\Setup\EavSetup;
use \Magento\Eav\Setup\EavSetupFactory;
use \Magento\Catalog\Setup\CategorySetupFactory;
class InstallData implements InstallDataInterface
{
protected $_eavSetupFactory;
protected $_categorySetupFactory;
public function __construct(
EavSetupFactory $eavSetupFactory,
CategorySetupFactory $categorySetupFactory
) {
$this->_eavSetupFactory = $eavSetupFactory;
$this->_categorySetupFactory = $categorySetupFactory;
}
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$eavSetup = $this->_eavSetupFactory->create(['setup' => $setup]);
$setup = $this->_categorySetupFactory->create(['setup' => $setup]);
$setup->addAttribute(
\Magento\Catalog\Model\Category::ENTITY, 'grid_image', [
'type' => 'varchar',
'label' => 'Grid Image',
'input' => 'image',
'visible_on_front' => true,
'backend' => 'Magento\Catalog\Model\Category\Attribute\Backend\Image',
'required' => false,
'sort_order' => 9,
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
'group' => 'Content',
]
);
}
}
However, I am unable to access the actual attribute in the frontend. I'm grabbing the current category via the Registry, and find that the attribute simply isn't attached (tried checking using $category->debug()). Any ideas for how I can get access to it on the frontend?