asdqwerty Posted November 18, 2013 Share Posted November 18, 2013 Hi I'm wondering how to make a link change language and go back to the same page. This is a current link: <a href="index.php?id_lang=1"><img src="{$img_dir}flags/eng.png"></a> As you see it simply links to the homepage, is there a better way to make it stay on the same page as when the link was clicked? Regards Link to comment Share on other sites More sharing options...
NemoPS Posted November 18, 2013 Share Posted November 18, 2013 Are you using a custom theme? By default, it redirects to the same page (in ps 1.5.6 for example, but all previous did afaik) Link to comment Share on other sites More sharing options...
asdqwerty Posted November 18, 2013 Author Share Posted November 18, 2013 I am using my own custom theme yes. Instead of the language block I am just coding the links in in my header.tpl file. Regards Link to comment Share on other sites More sharing options...
vekia Posted November 18, 2013 Share Posted November 18, 2013 you need to use link object, then you will be properly redirected to page, where you were $link->getLanguageLink($language.id_lang)|escape:htmlall} 2 Link to comment Share on other sites More sharing options...
asdqwerty Posted November 19, 2013 Author Share Posted November 19, 2013 you need to use link object, then you will be properly redirected to page, where you were $link->getLanguageLink($language.id_lang)|escape:htmlall} Thanks thats almost it! Is there a way I can specify a language the link goes to? Or is there a way for me to just link it like this: <current page link>?id_lang=2 Thanks Link to comment Share on other sites More sharing options...
vekia Posted November 19, 2013 Share Posted November 19, 2013 if you will use friendly urls, your method (<current page link>?id_lang=2) will not work. urls to pages that you're trying to link, use always actual active language Link to comment Share on other sites More sharing options...
asdqwerty Posted November 19, 2013 Author Share Posted November 19, 2013 I abandoned my quest with this since it was a lot more work than I expected, so I just reworked the language block as I wanted it, thanks anyway! Regards 1 Link to comment Share on other sites More sharing options...
Bill Dalton Posted July 12, 2014 Share Posted July 12, 2014 Old Post but this worked great for me, thanks vekia. <a href="{$link->getLanguageLink(1)}" title="{l s='English' mod='blockpermanentlinks'}">{l s='English' mod='blockpermanentlinks'}</a> <a href="{$link->getLanguageLink(2)}" title="{l s='Français' mod='blockpermanentlinks'}">{l s='Français' mod='blockpermanentlinks'}</a> With friendly URLS on or off. Link to comment Share on other sites More sharing options...
Bill Dalton Posted July 14, 2014 Share Posted July 14, 2014 (edited) BLAST! It only works when the Smarty Cache is off. It is perfect when the cache is off, the link picks up the name of the English page and you switch to the French version. Anyone know how I can get this to work? Edited July 14, 2014 by Bill Dalton (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted July 14, 2014 Share Posted July 14, 2014 hello i think that it's something with core :f what ps version? Link to comment Share on other sites More sharing options...
Bill Dalton Posted July 14, 2014 Share Posted July 14, 2014 PS 1.5.6.2 I really don't get why it doesn't like cache. With cache off, $link->getLanguageLink(2) works perfectly. I can be on any English page, click the link and see the French version. But when cache is on this function simply gets the first link used in a session and than continues to use the first link regardless of page. I spent several hours yesterday trying to make a link that simply return the same page you are on in a specified language. $link->getLanguageLink(2) is the only one I can get to work properly but only if I turn off cache. Link to comment Share on other sites More sharing options...
Bill Dalton Posted July 14, 2014 Share Posted July 14, 2014 I cannot figure this out. Just when you think you have seen it all ... Link to comment Share on other sites More sharing options...
Bill Dalton Posted July 15, 2014 Share Posted July 15, 2014 (edited) In the end I went with just copying the code from the language block and adding in the markup. It actually is a better solution because the link only shows in the language of context. So for someone else that may want this here is the code from my Permanent Links Mod. <!-- Block permanent links module HEADER --> <section class="header-box blockpermanentlinks-header"> <ul id="header_links"> <li><a href="{$link->getPageLink('index.php')}" class="header_links_home"><i class="icon-circle-arrow-right"></i> {l s='Home' mod='blockpermanentlinks'}</a></li> <li id="header_link_sitemap"><a href="{$link->getPageLink('sitemap')}" title="{l s='sitemap' mod='blockpermanentlinks'}"><i class="icon-circle-arrow-right"></i> {l s='sitemap' mod='blockpermanentlinks'}</a></li> <li id="header_link_contact"><a href="{$link->getPageLink('contact', true)}" title="{l s='contact' mod='blockpermanentlinks'}"><i class="icon-circle-arrow-right"></i> {l s='Contact' mod='blockpermanentlinks'}</a></li> <li id="header_link_bookmark"> <script type="text/javascript">writeBookmarkLink('{$come_from}', '{$meta_title|addslashes|addslashes}', '<i class="icon-circle-arrow-right"></i> {l s='Bookmark' mod='blockpermanentlinks' js=1}');</script> </li> {foreach from=$languages key=k item=language name="languages"} <li {if $language.iso_code == $lang_iso}class="selected_language"{/if}> {if $language.iso_code != $lang_iso} {assign var=indice_lang value=$language.id_lang} {if isset($lang_rewrite_urls.$indice_lang)} <li id="header_link"><a href="{$lang_rewrite_urls.$indice_lang|escape:htmlall}"><i class="icon-circle-arrow-right"></i> {$language.name}</a></li> {else} <li id="header_link"><a href="{$link->getLanguageLink($language.id_lang)|escape:htmlall}"><i class="icon-circle-arrow-right"></i> {$language.name}</a></li> {/if} {/if} </li> {/foreach} </ul> Edited July 15, 2014 by Bill Dalton (see edit history) Link to comment Share on other sites More sharing options...
Bill Dalton Posted July 15, 2014 Share Posted July 15, 2014 Spoke too soon again. When the smarty cache is turned on, this code fails. It works for several pages and then begins to return incorrect links. If anyone can point me to what I'm doing wrong it would be of great help. Link to comment Share on other sites More sharing options...
vekia Posted July 15, 2014 Share Posted July 15, 2014 strange im trying it on my own and it generates correct links perhaps you use some overrides of link class? your module uses caching? (php file) Link to comment Share on other sites More sharing options...
Bill Dalton Posted July 15, 2014 Share Posted July 15, 2014 I can use all code above with cache off, but if I turn cache on the links stop working after a few clicks. I even copied the exact code from Language Block and pasted it into the Permanent Links .tpl, and even that code will not work when the cache is on, even though the same code runs perfectly in the Language Block .tpl. Here is the site with cache on. http://scrubscanada.ca/scpsmay14/en/med-couture/38-med-couture-ez-flex-sport-neckline-top.html The language link in Permanent Links will work when you get to the page, but in just a few different pages it begins to send you to an incorrect page. I don't know why. Link to comment Share on other sites More sharing options...
Bill Dalton Posted July 15, 2014 Share Posted July 15, 2014 The fix turned out to be nice and simple. Something that I'm sure will prove useful now that I know. Smarty lets you use {nocache} {/nocache} and you can use it at line level for very fine control. Good read here if interested, http://www.smarty.net/docs/en/caching.cacheable.tpl Using {nocache} all of the above code works, but in the end I like this version best, same as above but with {nocache} tags. <!-- Block permanent links module HEADER --> <section class="header-box blockpermanentlinks-header"> <ul id="header_links"> <li><a href="{$link->getPageLink('index.php')}" class="header_links_home"><i class="icon-circle-arrow-right"></i> {l s='Home' mod='blockpermanentlinks'}</a></li> <li id="header_link_sitemap"><a href="{$link->getPageLink('sitemap')}" title="{l s='sitemap' mod='blockpermanentlinks'}"><i class="icon-circle-arrow-right"></i> {l s='sitemap' mod='blockpermanentlinks'}</a></li> <li id="header_link_contact"><a href="{$link->getPageLink('contact', true)}" title="{l s='contact' mod='blockpermanentlinks'}"><i class="icon-circle-arrow-right"></i> {l s='Contact' mod='blockpermanentlinks'}</a></li> <li id="header_link_bookmark"> <script type="text/javascript">writeBookmarkLink('{$come_from}', '{$meta_title|addslashes|addslashes}', '<i class="icon-circle-arrow-right"></i> {l s='Bookmark' mod='blockpermanentlinks' js=1}');</script> </li> {nocache} {foreach from=$languages key=k item=language name="languages"} <li {if $language.iso_code == $lang_iso}class="selected_language"{/if}> {if $language.iso_code != $lang_iso} {assign var=indice_lang value=$language.id_lang} {if isset($lang_rewrite_urls.$indice_lang)} <li id="header_link"><a href="{$lang_rewrite_urls.$indice_lang|escape:htmlall}"><i class="icon-circle-arrow-right"></i> {$language.name}</a></li> {else} <li id="header_link"><a href="{$link->getLanguageLink($language.id_lang)|escape:htmlall}"><i class="icon-circle-arrow-right"></i> {$language.name}</a></li> {/if} {/if} </li> {/foreach} {/nocache} </ul> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now