Thursday 24 January 2019

How to render template for custom module in drupal 8?

It is easy way to render/call template(.html.twig) file for custom module in drupal 8, But here concept is slightly different from drupal 7.
First we will go to the Controller file:
Like our controller name is ContactController.php so we will write there code like.
//Go to the ContactController.php file..
/**
 * @file
 * Contains \Drupal\contact\Controller\ContactController.
 */

namespace Drupal\contact\Controller;
use Drupal\node\Entity\Node;
use Drupal\Core\Controller\ControllerBase;


class Contactv4Controller extends ControllerBase {  
    public function indexv2() {
     
      $data = "<div>Testing</div>";
     
      return [
       '#theme'  => 'specific_contact',
       '#contact'   => $data,
    ];
  }
}

// Then go to the contact.module file.
/**
* Implements hook_theme() to add the template definition..
**/
function contact_theme($existing, $type, $theme, $path) {
  return array(
       'specific_contact' => [
        'variables' => [
            'contact' => NULL,
       ]
    ]
  );
}
 
// Now in the create template folder and the file with name of 'specific_contact.html.twig'.
And render the variable there like: <p> {{ contact }} </p>
And clear the cache after this.
Now Front end result will be 'Testing' on new template page.


Note: If have any suggestions or issue regarding 'How to render template for custom module in drupal 8?' then you can ask by comments.   

Friday 11 January 2019

How to optimize the website in drupal 8 ?

Sometimes we create the website but that is not quickly responded and we don't get proper users response on site. Sometime our client want to Speed Up the website and we just go through the Admin section and Aggregate CSS and JS files. But that is not properly working as our expectation. So here very first time we have some suggestion in easy way to Speed up the website and that will surly Speed up our website . That is tested with our projects. Please have a look suggestions for Desktop and Mobile both end..

Suggestions:
- Module to speed up site(Image Lazyloader, ADVANCED CSS/JS AGGREGATION)  --> We have added screen shot for checked options.
- Aggregated CSS/JS code.
- Remove extra CSS/JS that is not use full for front page.
- Set required custom image size(image styling) for page images.
- Create custom size of images(Home -> Administration -> Configuration -> Media -> Add image style).
- Follow Google page speed suggestion.
- Reduces Request to server.
- Uninstall extra modules.
- Use Optimized Image.
- Use critical css only ,use only those css/js which you need most.
- Add Async and defer attribute.
- Eliminate render-blocking resources.











Note: If have any suggestions or issue regarding 'How to optimize the website 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...