Include templates based on current language with drupal

那年仲夏 提交于 2019-12-11 07:35:09

问题


I'm looking for a fast way to display a particular template file based on the current language of the page.

Let's say I have two languages : english and french (english being the default)

I have various templates files, like : page.tpl.php page-node-11.tpl.php in my theme directory.

I'd like to find out a way to include these files based on the current languages; so for example if the current language is 'english', it will include 'page.tpl.php', if the current language is 'french' it will include 'fr/page.tpl.php'.

I'm sure it's pretty straight forward, but can't figure out how; in template.php ?

Thanks for any help.


回答1:


Assuming you're using the Internationalization module, rather than changing the template per language, you may want to consider taking advantage of the CSS class set on the body tag. I've used that technique on sites before and it was easier than dealing with another template file. If you don't use the i18n module, you could still add the body class inside a preprocess_page function.

If a body class won't work for you, you could look at the patch from the issue above for an example of how to add the language to the variables array during preprocessing. Then see the Working with template suggestions handbook page for how to add template suggestions based on the newly added language info.



来源:https://stackoverflow.com/questions/5004041/include-templates-based-on-current-language-with-drupal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!