I have installed ECK module in my website. Using it I have created a "report eck" entity in which I have different bundles like section, notes, etc., each containing different fields. I have my content type "Report" in which I have referred "report eck" entity using entity reference field. Now, in my nice template, I need to get various values including the bundle type, in which I am facing lots of trouble. My bundle type is coming up as following when I am doing kint() on my reference field, but I am not able to get this bundle type and many other values, please guide. enter image description here

Also, it seems to be a protected values, so I navigated to "Available Methods" tabs and found method 'getEntityKey()' which seems to be useful, but how can I use it in twig template??

enter image description here


2 Answers 2


These are protected. You need to use any available getters to access them. Example, for nodes, the method is getType(). $node->getType(). Most generic entities should have a bundle() method that returns type.



$bundle = $myEntity->bundle();

$variables['bundle'] = $bundle;

Twig: {{ bundle }}

  • I found some methods in the 'Available Methods' tab, but how to implement them in a twig template?
    – Dev
    Jun 6, 2017 at 13:15
  • You can't implement PHP methods or PHP code in a twig template. You can only inject new variables from the .theme file in a preprocess hook.
    – Kevin
    Jun 6, 2017 at 13:16
  • I know I can not implement PHP in twig template, but I thought there will be some way to access these variables in template, I have updated my question, please have a look
    – Dev
    Jun 6, 2017 at 13:22
  • His code example is for twig template not PHP one. May 26, 2021 at 0:17

I will go for render option and use the template instead of manually accessing values. Alternatively, you can go for custom twig functions or filters to access referenced field values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.