I'm trying to declare if a user is on a /uk or /us version of the site.

domain.com/uk/ domain.com/us/

{% if (craft.app.request.segments == '/uk/') %}
UK site
{% endif %}

This doesnt work. Can anyone explain why and where I'm going wrong?

Thank you

2 Answers 2


The request segments will come back as an array, where each part between slashes will be an array element so mysite.com/first/second/third gives segments [first,second,third]

If you're just looking for the first segment, you can try (craft.app.request.segments|first == 'uk') to get that information.

  • Unfortunately this doesn't work.
    – HeyImArt
    Jun 11, 2020 at 14:05
  • That should work. With devMode on, when you do a {{ dump(craft.app.request.segments) }} what are you getting? Jun 11, 2020 at 18:27

Assuming you're using Craft's multi-site functionality(?), you'll want to use something like {{ currentSite.handle }} to check which site they're on. For multiple sites configured to use sub-directories from a single domain name, the first segment of the URL is considered to be part of the siteUrl and will not be returned in the segments array.

Your Answer

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

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