Showing posts with label twig fields render. Show all posts
Showing posts with label twig fields render. Show all posts

Wednesday 4 July 2018

Drupal 8 base_path and base_path_url.

We have syntax change in drupal 8 for base_path and base_path_url, Please have a look..

  • base_path = base_path();  // This code is for base_url of site.                                                    
  • base_path_url = \Drupal::request()->getpathInfo();  // This code for current page path.
  • Front page = {{ url('<front>') }}  // This code is for front page url.
  • Theme directory path = url('{{ base_path ~ directory }} //This code is for theme's root directory
Note: If have any suggestions or issue regarding 'Drupal 8 base_path and base_path_url' then you can ask by comments.

Check AND /OR use in twig file.

Check AND /OR use in twig file, look at the syntax..

For OR Syntax..

{% if content.field_machine_name|render or content.field_machine_name|render %}
        /* write comment here */
{% endif %}

For AND Syntax..
 
{% if content.field_machine_name|render and content.field_machine_name|render %}
        /* write comment here */
{% endif %} 

Note: If have any suggestions or issue regarding 'Check AND /OR use in twig file' then you can ask by comments.

Check twig file field is empty or not.

For check Twig file field is empty or not, look at the syntax..
 
{% if content.field_machine_name[0] is not empty %}
           /* write comment here */
{% else %}
          /* write comment here */
{% endif %}

                                 OR

{% if content.field_machine_name|render %}
       /* write comment here */
{% endif %}


Note: If have any suggestions or issue regarding 'Check twig file field is empty or not' then you can ask by comments.

Tuesday 3 July 2018

Break line in between variables of twig file.

We can break the lines in between variables in twig file with add div syntax, please have a look.

<div>{{ content.field_machine_name }}</div>   //for insert line break 

 Note: If have any suggestions or issue regarding 'Break line in between variables of twig file' then you can ask by comments.

Friday 29 June 2018

Twig file feature in Drupal 8.

We use '.tpl.php' extension for druapl 7 but now in case of drupal 8 extension is '.html.twig'.
Lets talk about twig file..
  1. For node id in twig file syntax..  {{ node.id }}
  2. For node title in twig file syntax.. {{ node.label }}
  3. For node body in twig file syntax.. {{ node.body }} 
  4. For node any field.. {{ content.field_machine_name[0] }} or {{ content.field_machine_name.0 }}
if else syntax..

{% if ... %}
            /* write comment here */
{% else %}
           /* write comment here */
{% endif %}


For create variable in twig file syntax..
 
{% set variable name = "variable value" %}  then write {{  variable name }} and use it easily.

 Note: If have any suggestions or issue regarding 'Twig file feature 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...