drupal 7 - what is the use of classes_array in drupal7 template.php -


in template.php many times used classes_array..am not getting meaning , why using,..what purpose of classes_array , when have use in drupal7 .tpl.php

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

$variables['classes_array'] used in preprocess functions. adds classes used in rendering element processed. in example, class named "debug" added html container of rendered element: if actual code

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

your theme output body tag like

<body class='debug [...other classes...]'> 

for users administrator role.

you can add classes nodes, or other kind of elements preprocess hook available. e.g. write node preprocess function:

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

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

in general, not find $classes_array among defined variables in tpl.php files. theme will, of times, implode them in $classes variable. must noted, however, kind of confusion arised on time, different themes may use $classes_array, $attribute_array, $classes, $attributes['class'] , on same purpose, should check theme's documentation find out suits case.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -