Home » Magento, Magento 216 January 2017

Magento 2: Get Attribute Id, Name, Value from Attribute Code

This article shows how you can get attribute name or label, id, entity_type, etc. by attribute code in Magento 2.

If you would like get attribute name and value in Magento 1 then you may refer to this article: Magento: How to get attribute name and value?

I will be showing both Dependency Injection (DI) way and Object Manager way.

Using Dependency Injection (DI): Get attribute id, name and value from attribute code

Here is the code that you need to write in your Block class.

Below are the code to be written in template file.

Here, we will be fetching attribute data for attribute “color” of “product”.

It’s better to use the above code to fetch attribute info. But, here is the other way to fetch attribute info by attribute code.

Getting all attributes with the attribute code ‘name’.

Get attribute info with attribute code ‘name’ of the product entity type only.

Using Object Manager: Get attribute info and it’s options

Hope this helps. Thanks.

Magento 2

Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed

Comments are closed.