Skip to main content

Posts

Showing posts with the label twig

Component-Based Theming in Drupal 8

About Pattern Lab : The PHP version of Pattern Lab is, at its core, a static site generator.   To use the basic features of Pattern Lab, you must have  PHP 5.3+  installed Componentization has become a growing consideration in most of the web application development firms. The reasons are obvious, instead of reinventing the wheels again and again, why don’t we re-use them. Why should you follow component driven front-end development approach? Allows for re-use of Components A component-based UI approach accelerates the development You can completely decouple the front-end development Testing becomes easier Parallelize development Flexible project workflow How to use component driven front-end development approach In Drupal? One of the most popular tools for component driven front-end development is  Pattern Lab .   What makes Pattern Lab so famous is its flexibility in pairing up with the Atomic Design methodology.   Addition of tw...

twig templating

Twig is a PHP-based compiled templating language. When your web page renders, the Twig engine takes the template and converts it into a 'compiled' PHP template which is stored in a protected directory in sites/default/files/php/twig. The compilation is done once, template files are cached for reuse and are recompiled on clearing the Twig cache. Preprocessing for Template Files : The main role of the preprocessors is to set up variables to be placed within the template (.tpl.php) or twig files. Every layer in Drupal from core, modules, engines and themes can have numerous preprocessors Mainly There are two main functions to override the  code .. preprocess and preprocess_HOOKS respectly, first is template,module,engine,theme, Most used is theme preprocess and process THEME_preprocess(&$variables,$hook) Where hooks are like menu,page,html, etc THEME_preprocess_HOOK(&$variables) Features of Twig :  Twig Block in Drupal 8 : It is performed by tempelate in...

Drupal 8 Themings

Why Create Subtheme in drupal 8 , If you directly change on main theme and update the new version then all the changes would be lost. YAML file structure 1 - Tabs are NOT allowed. Use spaces ONLY. 2 - Properties and lists MUST be indented by two (2) spaces let theme name is fullfillness What are the files needed to create a theme 1 - .info.yml 2 - .libraries.yml 3 - .breakpoints.yml 4 - .theme  - create fullfillness.info.yml   - if theme has space then, replace the underscore with space in file name and folder name  - minimum required properties (name, type, and core)  key value pair in the info.yml file libraries (optional) A list of libraries (which can contain both CSS and JavaScript assets) to add to all pages where the theme is active. Read more about themes and asset libraries. libraries:   - fluffiness/global-styling libraries-override (optional) A collection of libraries and assets to override. Read more at Overridi...

Views Template rendering in Drupal 8

File name suggessations are as follows:  [base template name]--[view machine name]--[view display id].html.twig [base template name]--[view machine name]--[view display type].html.twig [base template name]--[view display type].html.twig [base template name]--[view machine name].html.twig [base template name].html.twig example I used for an "unformatted list" with machine name "view_name" and with a single block, "block_1" views-view-unformatted--view-name--block-1.html.twig Custom Theme template with modules module name = product_view Add .module file /**  * Implements hook_theme().  */ function product_view_theme() {   return [     'product_view' => [       'variables' => [         'product_info' => [],       ],     ],   ]; } In controller return the theme with data:: $aa = array ( 'name' => 'raj' , 'age' => 20 );...

Debug print drupal 8 variables

Use Devel and kint , and search Kint NOTE: Please make sure devel profile must be kint ksm($form);  // print the form with search option in kint 1 - $form_state->getValues(); // Shows all the form field value 2 -  $form_state->getUserInput(); //to get the user input including buttons clicked +++++++++++++++++++++++ dump(_context|keys) }} // in twig file Compare string in Twig file  {% set form_id = form.custom_data.form_id %} {% if form_id == "node_story_edit_form" %}  Yes i am here  {% endif %}    2 - get the # valued of form in twig templates, : All the array and object value can get by  dot(.) operation while # value get by direct array like  below, if($form['#form_id'] == 'node_video_form' || $form['#form_id'] == 'node_video_edit_form'){        $form['#custom_data'] = array('custom_form_id' => $form['#form_id']);    ksm($form); } in twig file : {{ kint(form['...

How to theme form in Drupal 8

https://www.bryanbraun.com/2013/08/17/using-hook-form-base-form-id-alter/ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element; /* * Implement hook_form_base_id_alter() */ function atadmin_form_node_form_alter(&$form, FormStateInterface $form_state) { $node = $form_state->getFormObject()->getEntity(); if($form['#form_id'] == 'node_story_form' || $form['#form_id'] == 'node_story_edit_form'){ $form['#theme'] = array('at_node_story_form'); }elseif($form['#form_id'] == 'node_video_form' || $form['#form_id'] == 'node_video_edit_form'){ $form['#theme'] = array('at_node_video_form'); }elseif($form['#form_id'] == 'node_photo_gallery_form' || $form['#form_id'] == 'node_photo_gallery_edit_form'){ $form['#theme'] = array('at_node_photo_gallery_form'); }elseif($form['#form_id'] == 'node_po...