Is it possible to insert additional class to the body tag through the page.tpl.php file but with the condition:

$language->language == 'zh-hans'

in an IF statement?

I tried adding the following code to the template.php:

function MYTHEME_preprocess_html(&$variables, $hook) {
global $language;
if ($language->language == 'zh-hans') {
    $variables['classes_array'][] = "zh-hans";


but I'm not sure if the function is supposed to be used like this. The class does not appear.

  • Why would you need that? If you have i18n installed and enabled, you should already have classes like i18n-en on your <body> – Mołot May 14 '14 at 8:13
  • But of course yes, it is possible. Post the code you tried and how it failed, if you want us to tell what was wrong. – Mołot May 14 '14 at 8:18
  • edited question. – huijing May 14 '14 at 10:32
  • @HuiJingChen You're new to PHP I take it? You'll need to learn a bit more about the language before you can write Drupal code. As a starting point, ask yourself where $language is being defined in your code (it happens to be a global variable, so Google that). Even after the edit this is still a duplicate of the other question; using a slightly different conditional isn't enough to warrant a new question asking essentially the same thing – Clive May 14 '14 at 10:47
  • noted. i apologise for the duplicate. – huijing May 14 '14 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.