Showing posts with label term id. Show all posts
Showing posts with label term id. Show all posts

Tuesday 19 March 2019

How to get the Parent id from term id in drupal 8?

It's easy way to tackle this problem, Sometimes we face this issue and take the query help and get the parent id, but we have here solution for this issue.

Just write the loadParent syntax as per given instructions:

Syntax:

$term_id = $node->get('field_category')->target_id;
$term = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->load($term_id);
$parentids = $term->parent->target_id;

OR

 $parent = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadParents($term_id);   // here term_id is child term id
 $parent = reset($parent); //reset the parent array
 $parentids = $parent->id();    //get the parent id  


Note: If have any suggestions or issue regarding 'How to get the Parent id from term id in drupal 8?' then you can ask by comments.

Tuesday 7 August 2018

How to render fields on Taxonomy twig templates?

It is easy to call/render taxonomy fields on taxonomy template. We just have to create template file according to vocabulary machine name like 'application landing page' is taxonomy and machine name will be 'application_landing_page', but our template name will be 'taxonomy-term--application-landing-page.html.twig' as per Drupal 8(Symphony) Syntax.

and we will call/render fields like..


Term id: {{ term.id }}  // term id

Term Url: {{ url }}  // current page url

Term Title: {{ term.label }}  // term title

Term Image: {{ file_url(term.field_product_group_image.entity.uri.value) }}  // show url of product group image is the image field in taxonomy

Term Description/body: {{ content.description }}

Term Link field: {{ term.field_link.0.url }}

Term Link Title field: {{ term.field_link.0.title }}

Term custom field: {{ content.field_machine_name }}


If we want to check any field value exist or not then we are giving an example like we have field 'line of business' so machine name will be line_of_busines and we will check by..

{% if content.field_line_of_busines is not empty %}

{{ content.field_line_of_busines }}

{% endif %}



Note: If have any suggestions or issue regarding 'How to render fields on Taxonomy twig templates' then you can ask by comments.

How to resolve max execution time error in drupal ?

When you found error regarding 'max_execution_time' exceed, then you can follow steps for resolve this error: Steps:   You can put t...