Drupal 8 Query to get category info

Drupal 8 Query to get category info

Here is the Drupal 8 Query to get category info
here category name “color_cat”

$vid = ‘color_cat’;
$parent_tid = 0;//parent id
$depth = 2; //depth upto which level you want
$load_entities = FALSE;
$cat_data= \Drupal::entityTypeManager()->getStorage(‘taxonomy_term’)->loadTree($vid,
$parent_tid, $depth, $load_entities);

$variables[‘color_cat’] = $cat_data;

add below code inside your .theme file

in .twig file you have use below twig code to display category name


  {% for key1, value in color_cat %}
                

{{ color_cat[key1]['name'] }} {% endfor %}

My Thought

Your email address will not be published. Required fields are marked *

Our Tool : hike percentage calculator