We can get attribute data by attribute code by just passing the attribute code in Magento 2.
We have taken entity_type_code value as Catalog_Product for a demo in the below code, You can get any entity_type_code as per your requirement.
<?php
public function __construct(
\Magento\Eav\Model\Entity\Attribute $entityAttribute
) {
$this->entityAttribute = $entityAttribute;
}
/**
* Load attribute data by code
* @return \Magento\Eav\Model\Entity\Attribute
*/
public function getAttributeInfo($attributeCode)
{
return $this->entityAttribute->loadByCode('catalog_product', $attributeCode);
}
Now, Call getAttributeInfo() function from template,
$attributInfo = $this->getAttributeInfo('color');
echo '<pre>';print_r($attributInfo->debug());
The result will be like the below array for color product attributes,
Array
(
[attribute_id] => 93
[entity_type_id] => 4
[attribute_code] => color
[attribute_model] => Magento\Catalog\Model\ResourceModel\Eav\Attribute
[backend_model] => Magento\Eav\Model\Entity\Attribute\Backend\DefaultBackend
[backend_type] => int
[frontend_input] => select
[frontend_label] => Color
[is_required] => 0
[is_user_defined] => 1
[is_unique] => 0
[is_global] => 1
[is_visible] => 1
[is_searchable] => 1
[is_filterable] => 1
[is_comparable] => 1
[is_visible_on_front] => 0
[is_html_allowed_on_front] => 0
[is_used_for_price_rules] => 0
[is_filterable_in_search] => 1
[used_in_product_listing] => 0
[used_for_sort_by] => 0
[apply_to] => simple,virtual,configurable
[is_visible_in_advanced_search] => 0
[position] => 0
[is_wysiwyg_enabled] => 0
[is_used_for_promo_rules] => 0
[is_required_in_admin_store] => 0
[is_used_in_grid] => 1
[is_visible_in_grid] => 0
[is_filterable_in_grid] => 1
[search_weight] => 1
[additional_data] => {"update_product_preview_image":"0","use_product_image_for_swatch":"0","swatch_input_type":"visual"}
)