I have create a Magento Theme and also add attribute with a drop-down option value.
Now I wanted to display the value of the attribute in my Magento_theme::advancesearch.phtml
file.
i use in my advancesearch.phtml
/**
* Get attribute info by attribute code and entity type
*/
$attributeCode = 'color';
$entityType = 'catalog_product';
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
/*$attributeInfo = $objectManager->get(\Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection::class)
->setCodeFilter($attributeCode)
->getFirstItem();*/
$attributeInfo = $objectManager->get(\Magento\Eav\Model\Entity\Attribute::class)
->loadByCode($entityType, $attributeCode);
//var_dump($attributeInfo->getData()); exit;
/**
* Get all options name and value of the attribute
*/
$attributeId = $attributeInfo->getAttributeId();
$attributeOptionAll = $objectManager->get(\Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\Collection::class)
->setPositionOrder('asc')
->setAttributeFilter($attributeId)
->setStoreFilter()
->load();
//var_dump($attributeOptionAll->getData()); exit;
/**
* Fetch particular option's name and value of the attribute
*/
$optionId = YOUR_OPTION_ID;
$attributeOptionSingle = $objectManager->get(\Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\Collection::class)
->setPositionOrder('asc')
->setAttributeFilter($attributeId)
->setIdFilter($optionId)
->setStoreFilter()
->load()
->getFirstItem();
//var_dump($attributeOptionSingle->getData()); exit;
But this showing nothing to my theme. Here is my default.xml,
<container name="header_advance_search" as="header_advance_search" label="header custom" htmlTag="div" htmlClass="advance_search">
<block class="Magento\Framework\View\Element\Template" name="advance_search" as="advance_search" template="Magento_Theme::advance_search.phtml"></block>
</container>
<move element="advance_search" destination="store.menu"/>
In Magento 1 I can use Mage: and get value of attribute product information and many more in any phtml file on Theme. But here face problem. Is there any solution?