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

Tuesday 27 August 2019

Why Drupal 8 Performance is better than Drupal 7?

Drupal 8 comes with Symfony framework, a high performing PHP framework with code security. Drupal 8 is faster than Drupal 7, here we have some points that can prove who is faster version in Drupal. 

1. Drupal 8 now turned on dynamic caching.
2. Drupal 8 turned on 6 week page caching for anonymous users. This makes Drupal 8 serving    anonymous user very fast.
3. Even logged in users can Benefit from performance improvement.
4. Drupal 8 does not send JavaScript to all pages, unless you need to use it.
5. Only place where Drupal 8 is slow in cold caching, if user is the first visitor of website in Drupal 8, it will be slower than Drupal 7 but because of cache improvement next time visitor will hit the page, it will be faster in Drupal 8.
6. Drupal 8 uses breakpoint media queries, which saves extra efforts to make a website responsive but in Drupal 7 does not use breakpoint media queries and has a different approach to manage how the site appears on different devices screens.
7. Drupal 8 uses Twig as a template engine. Twig is part of Symfony 2 framework and PHP based compiled template engine, however Drupal 7 uses the PHP template as default template engine and users create the templates by PHP code.
8. Symfony framework makes Drupal 8 stronger than Drupal 7 to develop secure and robust website or web applications.
9. Drupal 7 does not have powerful framework to manage its codebase. Developers still use Drupal 7 but its lack of framework features makes it hard to manage code.


Note: Why Drupal 8 Performance is better than Drupal 7?

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 11 December 2018

How to use country timezone in our Twig file ?

If we want to change the 'DATE' filter in you TWIG file, its easy to use Timezone.
here is the good example for this issue.

Example:
{{ "now"|date("m/d/Y H:i", "Europe/Paris") }}  //For Europe Paris region timezone
{{ "now"|date("m/d/Y H:i", "Asia/Calcutta") }}  //For Asia Calcutta region timezone
{{ "now"|date("m/d/Y H:i", "Europe/Berlin") }}  //For Europe Berlin region timezone

So same like we can use for other countries region time in our TWIG file.


Note: If have any suggestions or issue regarding 'How to use country timezone in our Twig file ?' then you can ask by comments.  

Wednesday 5 September 2018

Paragraph fields render in drupal 8 Node Twig template.

If we want to load paragraph entity fields on node twig template. It's easy to load paragraph entity, Please have a look..

{# call to paragraph entity fields on node twig #}

{{ node.field_professional_features.entity.field_professional_services_name.value }}
 // here `field_professional_features` is the content type field and `field_professional_services_name` is the related paragraph field..

{{ node.field_professional_features.entity.field_professional_services_summ.value }}
  // here `field_professional_features` is the content type field and `field_professional_services_summ` is the related paragraph field..

// here we are calling paragraph image field..

{% for key, image in node.field_professional_features %}
// here `field_professional_features` is the content type field..
{%if image.entity %}
{% set paragraph = image.entity %}
{% set file = paragraph.field_professional_services_imag.entity %}
 // here `field_professional_services_imag` is the related paragraph field..
{% set uri = file_url(file.uri.value) %}

<img src="{{ uri }}" alt="{{ paragraph.name.value }}" />

{% endif %}
{% endfor %} 



Note: If have any suggestions or issue regarding 'Paragraph fields render in drupal 8 Twig template.' then you can ask by comments.  

Tuesday 4 September 2018

Replace any string or value in twig template variable.

If we want to Replace the value in twig template then we have an example and syntax, please have a look..
{#
    ****  replace '-' with '$' sign in vidyard ID ****  
#}

{% set twig_content_variable  = node.field_resources_vidyard_id.value  %}   // here we are applying on field_resources_vidyard_id field..
{% set replace_value_var      = '-' %}
{% set replace_with_value_var = '$' %}
{%if twig_content_variable %}
   {% set vidyard_function_id = twig_content_variable|replace({ '-': '$' }) %}
{% endif %}


Note: If have any suggestions or issue regarding 'Replace any string or value in twig template variable.' then you can ask by comments. 

Monday 6 August 2018

Naming convention for node/content type template in drupal 8.

The naming convention of node/content type is very simple and we will explain by example here..

Example 1. If we have content type with name of 'customer story' so our this content type machine name will be 'customer_story' but we will take as a 'node--customer-story--full.html.twig' in naming convention.

Example 2. If we have content type with name of 'products' so our this content type machine name will be 'products' but we will take as a 'node--products--full.html.twig' in naming convention.

Example 3. If we have basic page single node like node id '58', So we will take as a 'node--58.html.twig' in naming convention.


Note: If have any suggestions or issue regarding 'Naming convention for node/content type template' then you can ask by comments.

Friday 3 August 2018

Naming convention for taxonomy template in drupal 8.

The naming convention of taxonomy is very simple and we will explain by..

Example 1. If we have taxonomy with name of 'product groups' so our this taxonomy machine name will be 'product_groups' but we will take as a 'taxonomy-term--product-groups.html.twig' in naming convention.

Example 2. If we have taxonomy with name of 'service support' so our this taxonomy machine name will be 'service_support' but we will take as a 'taxonomy-term--services-support.html.twig' in naming convention.


Note: If have any suggestions or issue regarding 'Naming convention for taxonomy template' then you can ask by comments.

Thursday 5 July 2018

Loop in twig file drupal 8.

Here we have syntax of for/foreach loop in Twig file. Please have a look the syntax..
Suppose we have array with name of 'data', so our for loop for twig will be.

{% for key, value in data %}
      {{ key }} | {{ value }}
{% endfor %}

                      OR

In case we need key with value then our syntax will be..

<ul>
 {% for key, value in data %}
   {% if key!= ' '%}

      <li class="{{ key }}"> {{ value }}</li>
    {% endif %}
{% endfor %}
</ul>

                       OR

In case we just need value without key then our syntax will be..

{% for value in data %}
   {{ value }}     
{% endfor %}

Note: If have any suggestions or issue regarding 'Loop in twig file drupal 8' then you can ask by comments.

Wednesday 4 July 2018

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.

New features in Drupal 8.

I am going to start describe few new things in Drupal 8 in easy way.

Now in drupal 8 version uses Symfony few Components, rather than all of Symfony. If you want to check the list of use components in druapl 8. You can check in 'core/composer.json' file.

  1. We will render/call all variables of twig file in double Curly Braces/Brackets, Syntax..  {{ write variable name here }}   

      2. For comment in twig file we have to use # keyword, Syntax..  

          {#{ write variable name here }#}   or   {#  commenting syntax  #}

 Note: If have any suggestions or issue regarding 'New features 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...