I need to have 2 separate front page tpl pages for a multilanguage site I'm building, one for the english layout and one for the chinese layout. If the default language is zh-hans, I would like it to serve the custom tpl page-cnfront.tpl.php.

I managed to find an answer to my question for Drupal 6, which provided the following code:

function mytheme_preprocess_page(&$variables) {
  global $language;
  if (drupal_is_front_page() && $language->language == 'en') {
    $variables['template_file'] = 'page-customfront';

I tried to modify it for my site in Drupal 7 like so:

function mytheme_preprocess_page(&$vars) {
  global $language;
  if (drupal_is_front_page() && $language->language == 'zh-hans') {
    $vars['theme_hook_suggestions'] = 'page__cnfront';   

but I think something is wrong, because I get a WSOD when I add this to my template.php. What is the correct way to do this?

  • This post might be useful for you. Change templates based on path alias – kyletaylored May 7 '14 at 6:32
  • Please read this documentation page. And use it. And then you will know what exactly went wrong. I mean, even if you screwed this function call, it shouldn't really cause WSOD as it doe snot have any syntax errors in it. If anything, it should simply fail, silently or verbose. – Mołot May 7 '14 at 6:46
  • @KyleTaylored, this works for path alias, but I'm not using a path alias for the other language. Which is why I chose to detect language instead. – huijing May 7 '14 at 6:56
  • For the WSOD, because I got the error message: Fatal error: Cannot redeclare sfo_preprocess_page() (previously declared in...) Which is why I inferred it was a problem with the preprocess function code, and am trying to get some advice on the code itself. – huijing May 7 '14 at 6:56

I would suggest you to install the Variable translation (i18n_variable) from the Internationalization module. This allows you to specify a front page per language under /admin/config/system/site-information.

  • I did install that module, however, I need the front page to have different layouts for the 2 different languages. I currently am unable to get the chinese site to pick up the page--cnfront.tpl.php file though. – huijing May 7 '14 at 10:33
  • OK, you basically could just create two different nodes and style them accordingly with templates like node--nodeid.tpl.php or page--node--nodeid.tpl.php. See the Drupal 7 Template Suggestinon: drupal.org/node/1089656 – Lance May 7 '14 at 11:02
  • So essentially, I'll be creating a template specific to that particular node then using the variable translation settings to set it as the default front page for my other site? – huijing May 7 '14 at 12:56
  • Correct. Or do something more specific like a own content type for that. – Lance May 7 '14 at 15:42

theme_hook_suggestions is array

$vars['theme_hook_suggestions'] = array('page__cnfront');   

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.