3

I am making a super simple language switcher. And I was wondering if there is a way to get the baseUrl for a site by id or handle, something like this:

<a class="navbar-item" href="{{baseUrl.german}}"><img class="circular-square" src="/images/global/german.png" alt="Germany Flag" />DE<span class="sr-only">Deutsch</span></a>

What I'm trying to avoid doing is:

<a class="navbar-item" href="/de"><img class="circular-square" src="/images/global/german.png" alt="Germany Flag" />DE<span class="sr-only">Deutsch</span></a>

Or is that just how to you do?

1 Answer 1

5
{% set site = craft.app.getSites().getSiteById(1) %}
{% set site = craft.app.getSites().getSiteByHandle('handle') %}
{{ site.baseUrl }}

But I would rather suggest you to grab the entries URL for a certain site in your language switcher

{% set entryInOtherSite = craft.entries.id(entry.id).siteId(2).one() %}
{{ entry.getUrl() }}

I'm not sure why you even ask this question since everything is well documented here since you "answered" that question

1
  • What I was trying to do here is different than my previous post. Thanks for the help. Jul 2, 2018 at 13:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.