I have two language on my web, and want to set one of them active when user choose any language from them. I assign to Smarty variable with value of current language ({$current_language}), set in my CSS file active flag for .en-active, and .ru-active, and wrote that code
{if $current_lang eq 'ru'}
{assign var='ru_active' value="ru-active"}
{elseif $current_lang eq 'en'}
{assign var='en_active' value="en-active"}
{/if}
<a href="index.php?lang=ru" class="ru {$ru_active}"></a>
<a href="index.php?lang=en" class="en {$en_active}"></a>
All work fine, but mby there is more clean way to do that ?
I tried else do something like this, without if checking:
{assign var='ru_active' value={$current_lang|cat:"-active"}
{assign var='en_active' value={$current_lang|cat:"-active"}
<a href="index.php?lang=ru" class="ru {$ru_active}"></a>
<a href="index.php?lang=en" class="en {$en_active}"></a>
But i dont think that it's a good idea. So maybe somebody can suggest really cool and clean method to do that.
P.S I don't have my language list in array.
Maybe make something like that:
<style>
.{$current_lang}{
color: green;
}
</style>
"color: green;" you can replace with inside from your active class
Don't worry about using <style> </style>
in your .tpl code, it's ok.