2

I have a template called page-my-view.tpl.php that overrides a view page my-view.

I have directly put the title tags, description and h1 on this template file.

However I need different texts for these tags per language to avoid duplicated tags.

I have 2 languages on my site English and Japanese. Japanese is the default one with no prefix and English is with prefix "en".

So how can I make a condition on this template for currently viewed language?

  • You could use the $language variable. $language->language holds the language code. To put logical code in your template is not the best way though :) – hampusn Sep 11 '12 at 8:19
0

In your template file global variable $language is avaible,with below properties

'language' => 'en',
'name' => 'English',
'native' => 'English',
'direction' => 0,
'enabled' => 1,
'plurals' => 0,
'formula' => '',
'domain' => '',
'prefix' => '',
'weight' => 0,
'javascript' => ''

You can achieve your jobs with something like this // if global variable $language not avaible uncomment first line

 //    global $language;
if ($language->language == 'en') {
   // do your desires
  }
  • Note that page templates already have the $language variable. No need for global $language;. – hampusn Sep 11 '12 at 8:40
  • I know it my friend,I say it because he/she understand $language is global :). – Yusef Sep 11 '12 at 9:05
  • I guess that's a good reason, but as it stands now, he/she might as well think that it's not and start to always use global $language. :) – hampusn Sep 11 '12 at 9:24
  • appreciate .You right. :). – Yusef Sep 11 '12 at 9:30
  • Your welcome :) – Yusef Sep 12 '12 at 9:24

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.