douya2982 2014-03-21 13:19
浏览 42
已采纳

drupal 7 template.php中classes数组的用途是什么

in template.php many times they used classes_array..am not getting the meaning and why they using,..what is the purpose of classes_array and when we have to use that in drupal7 .tpl.php

    example code:
    if(in_array('administrator',array_values($variables['user']->roles)))
    {
     $variables['classes_array'][]="debug";
      }
  • 写回答

1条回答 默认 最新

  • dqo58772 2014-03-23 23:39
    关注

    $variables['classes_array'] is used in preprocess functions. It adds classes to be used in rendering the element to be processed. In your example, a class named "debug" will be added to the html container of the rendered element: if the actual code is

    function <YOUR THEME>_preprocess_html(&$variables) {
      if (in_array('administrator',array_values($variables['user']->roles))) {
        $variables['classes_array'][]="debug";
      }
    }
    

    your theme will output a body tag like

    <body class='debug [...OTHER CLASSES...]'>
    

    for users with administrator role.

    You can also add classes to nodes, or other kind of elements for which a preprocess hook is available. E.g. you could write a node preprocess function:

    function <YOUR THEME>_preprocess_node($variables) {
      $classes_array[] = 'my-class';
    }
    

    if you wanted to add 'my-class' to every node of your site.

    In general, you will not find $classes_array among the defined variables in tpl.php files. Your theme will, most of the times, implode them in a $classes variable. It must be noted, however, that a kind of confusion arised over time, so different themes may use $classes_array, $attribute_array, $classes, $attributes['class'] and so on for the same purpose, so you should check your theme's documentation to find out what suits your case.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?