Jump to content

Base url depend on language


Recommended Posts

Hello, what is the best way to call {$urls.base_url} from .tpl but depend on language?

So if there only one language it should return shop.com/ but if there is 2 or more langs - it should return iso of current lang shop.com/en/ for example.

Link to comment
Share on other sites

  • 2 weeks later...
On 7/3/2020 at 7:18 PM, ndiaga said:

Hi,

Try  to  use  :


{assign  var=context   value=Context::getContext()}

{assign  var=iso_lang  value=$context->language->iso_code}

<!  then  you  can  do -->

{$urls.base_url}$iso_lang

 

thank you, but It's not solve the main problem:

If you have only one language in shop - for example english. Then 

{$urls.base_url}{$iso_lang}example.html

generates wrong link:

shop.com/en/example.html

while the real link with shop with one languge will be 

shop.com/example.html

Link to comment
Share on other sites

  • 10 months later...

themes/classic/templates/_partials/header.tpl
themes/classic/templates/checkout/_partials/header.tpl

This worked for me:

{assign var=context value=Context::getContext()}
{assign var=iso_lang value=$context->language->iso_code}

 

and the URL:   <a href="{$urls.base_url}{$iso_lang}/">

Dont forget to clear the prestashop cache!

Cheers!

Edited by ibisal (see edit history)
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...