Friday 29 March 2019

How to Check the Condition in Twig Template?

It's easy process to check the condition of our 'id' exist or not for particular variable render time in Twig template.
Like we have to check any "Product type" exist or not and then variable call there, So we are giving an example:
Example 1:
{% if node.field_product_type.value not in ['0', '2', '4', '5', '7'] %}
 /*** print variable here ***/
{% endif %}

Description: Here our condition is, if Product type of node value is not in these id's ['0', '2', '4', '5', '7'], then our variable will show the result otherwise not.

Example 2:
{% set node_id = node.id %}
{% if node_id in ['216','217','9','1258'] %} 
 /*** print variable here ***/
{% endif %}

Description: Here our condition is, if node id of node is in these id's ['216','217','9','1258'], then our variable will show the result otherwise not.


Note: If have any suggestions or issue regarding 'How to Check the Condition in Twig Template?' then you can ask by comments.

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 12 March 2019

How to encode url in drupal 8?

It's a easy way to encode url in drupal 8 twig template. We just have to follow the simple steps:
Step 1. First create a variable like given example.

Example:
{% set return_url = render_var(url('<front>')) ~ 'contact?msg=success&region=americas' %}

Description: here
   return_url is the variable name and
   url('<front>') is the front page url and
   contact?msg=success&region=americas this section we are concating with " ~ " Tilde sign and
   render_var is the render that full url.

Step 2. Now we have to pass the url in src like given example.

Example: https://www.google.com?Return_URL={{ return_url|url_encode}}

Description: So just call the "return_url" with "url_encode" function in url query string. That will return the encoded url.


Note: If have any suggestions or issue regarding 'How to encode url in drupal 8?' 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...