drupal主题开发

twig用法之: attributes.addClass 和 placeholder , block css, and override block

日期:2017-01-09 阅读:1980

dmandwp系统 - wordpress系统和DM系统区块建站>>


进入网易云课堂播放
    |    更多视频教程>

Adding CSS Classes to Blocks in Drupal 8

https://atendesigngroup.com/blog/adding-css-classes-blocks-drupal-8   

<?php
 
/**
 * Implements hook_theme_suggestions_HOOK_alter() for block templates.
 */
function my_theme_theme_suggestions_block_alter(array &$suggestions, array $variables) {
  $block_id = $variables['elements']['#id'];
 
  /* Uncomment the line below to see variables you can use to target a block */
  // print $block_id . '<br/>';
 
  /* Add classes based on the block id. */
  switch ($block_id) {
    /* Account Menu block */
    case 'account_menu':
      $suggestions[] = 'block__fancy';
      break;
  }
}

--------------------------

复制
core/modules/system/templates/input.html.twig 到
你的主题的template目录下

重命名为:input--email.html.twig 

twig用法之: attributes.addClass 和 placeholder

修改如下:
用到了三元(ternary)操作符:

{% set placeholder = attributes.placeholder ?attributes.placeholder : 'email@example.com' %}

<input{{ attributes.addClass('input__email') }}/>{{children }}

如果如下图:

<<点击返回

Drupal8主题开发视频教程 (进入专题>)