Quantcast
Channel: Lecciones Prácticas
Viewing all articles
Browse latest Browse all 33

Drupal 7: display language switcher in template [SOLVED]

$
0
0

Some days ago we learnt to display a search box in Drupal template files, and according to that post and the Drupal handbook rendering a language switcher block in your theme templates should be easy.

This should work:

<?php
$block = module_invoke('locale', 'block_view', 'language');
print render($block);
?>

Unfortunately, in my D7 it does not. What does work is this:

Add to template.php:

<?php
function block_render($module, $block_id) {
  $block = block_load($module, $block_id);
  $block_content = _block_render_blocks(array($block));
  $build = _block_get_renderable_array($block_content);
  $block_rendered = drupal_render($build);
  return $block_rendered;
}
?>

Add to page.tpl.php

<?php
  print block_render('locale', 'language');
?>

Now that the language switcher is rendering, you might want to customize its appeareance ;)


Viewing all articles
Browse latest Browse all 33

Trending Articles