Include templates based on current language with d

2019-08-02 14:59发布

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条回答
在下西门庆
2楼-- · 2019-08-02 15:20

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.

查看更多
登录 后发表回答