Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
improved formatting
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

get Get the user's current language code in views

On Drupal 8.7.10

How can I get the user's current language code into viewsin a view as a raw value, such as 'en'for example en or 'fr-ca'.fr-ca?

This is notisn't for filtering content. I need the raw value of the users' current language to pass into a urlURL for a third-party tool.

  I added a custom text field. Then placed in some twigTwig code. The code is just failing to the fallback 'else'else value.

Based on other forum posts, I'veI tried it these three ways:this code.

{% if language.getId() == 'en' %}
en
{% elseif language.getId() == 'es-us' %}
es-us
{% elseif language.getId() == 'en-us' %}
en-us
{% else %}
failed
{% endif %}
{% if language.getId() == 'en' %}
  en
{% elseif language.getId() == 'es-us' %}
  es-us
{% elseif language.getId() == 'en-us' %}
  en-us
{% else %}
  failed
{% endif %}

I'm getting 'failed'I get failed.

{% if language == 'en' %} 
en
{% elseif language == 'es-us' %}
es-us
{% elseif language == 'en-us' %}
en-us
{% else %}
failed
{% endif %}
{% if language == 'en' %} 
  en
{% elseif language == 'es-us' %}
  es-us
{% elseif language == 'en-us' %}
  en-us
{% else %}
  failed
{% endif %}

I still get 'failed'failed.

{% if language.id() == 'en' %}
en
{% elseif language.id() == 'es-us' %}
es-us
{% elseif language.id() == 'en-us' %}
en-us
{% else %}
failed
{% endif %}
{% if language.id() == 'en' %}
  en
{% elseif language.id() == 'es-us' %}
  es-us
{% elseif language.id() == 'en-us' %}
  en-us
{% else %}
  failed
{% endif %}

.... and, I still, 'failed' get the same output.

get user's current language code in views

On Drupal 8.7.10

How can I get the user's current language code into views as a raw value, such as 'en' or 'fr-ca'.

This is not for filtering content. I need the raw value of the users' current language to pass into a url for a third-party tool.

  I added a custom text field. Then placed in some twig code. The code is just failing to the fallback 'else' value.

Based on other forum posts, I've tried it these three ways:

{% if language.getId() == 'en' %}
en
{% elseif language.getId() == 'es-us' %}
es-us
{% elseif language.getId() == 'en-us' %}
en-us
{% else %}
failed
{% endif %}

I'm getting 'failed'

{% if language == 'en' %} 
en
{% elseif language == 'es-us' %}
es-us
{% elseif language == 'en-us' %}
en-us
{% else %}
failed
{% endif %}

still get 'failed'

{% if language.id() == 'en' %}
en
{% elseif language.id() == 'es-us' %}
es-us
{% elseif language.id() == 'en-us' %}
en-us
{% else %}
failed
{% endif %}

.... and, still, 'failed'.

Get the user's current language code

How can I get the user's current language code in a view as a raw value, for example en or fr-ca?

This isn't for filtering content. I need the raw value of the users' current language to pass into a URL for a third-party tool. I added a custom text field. Then placed in some Twig code. The code is just failing to the fallback else value.

Based on other forum posts, I tried this code.

{% if language.getId() == 'en' %}
  en
{% elseif language.getId() == 'es-us' %}
  es-us
{% elseif language.getId() == 'en-us' %}
  en-us
{% else %}
  failed
{% endif %}

I get failed.

{% if language == 'en' %} 
  en
{% elseif language == 'es-us' %}
  es-us
{% elseif language == 'en-us' %}
  en-us
{% else %}
  failed
{% endif %}

I still get failed.

{% if language.id() == 'en' %}
  en
{% elseif language.id() == 'es-us' %}
  es-us
{% elseif language.id() == 'en-us' %}
  en-us
{% else %}
  failed
{% endif %}

I still get the same output.

Rollback to Revision 2
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

How to get user's current language code in Views?views

On Drupal 8.7.10

How can I get the user's current language code into Viewsviews as a raw value, such as 'en' or 'fr-ca'?.

This is not for filtering content. I need the raw value of the users' current language to pass into a url for a third-party tool.

I added a custom text field. Then placed in some twig code. The code is just failing to the fallback 'else' value.

Based on other forum posts, I've tried it these three ways:

{% if language.getId() == 'en' %}
en
{% elseif language.getId() == 'es-us' %}
es-us
{% elseif language.getId() == 'en-us' %}
en-us
{% else %}
failed
{% endif %}

I'm getting 'failed'

{% if language == 'en' %} 
en
{% elseif language == 'es-us' %}
es-us
{% elseif language == 'en-us' %}
en-us
{% else %}
failed
{% endif %}

still get 'failed'

{% if language.id() == 'en' %}
en
{% elseif language.id() == 'es-us' %}
es-us
{% elseif language.id() == 'en-us' %}
en-us
{% else %}
failed
{% endif %}

.... and, still, 'failed'.

How to get user's current language code in Views?

On Drupal 8.7.10

How can I get the user's current language code into Views as a raw value, such as 'en' or 'fr-ca'?

This is not for filtering content. I need the raw value of the users' current language to pass into a url for a third-party tool.

I added a custom text field. Then placed in some twig code. The code is just failing to the fallback 'else' value.

Based on other posts, I've tried it these three ways:

{% if language.getId() == 'en' %}
en
{% elseif language.getId() == 'es-us' %}
es-us
{% elseif language.getId() == 'en-us' %}
en-us
{% else %}
failed
{% endif %}

I'm getting 'failed'

{% if language == 'en' %} 
en
{% elseif language == 'es-us' %}
es-us
{% elseif language == 'en-us' %}
en-us
{% else %}
failed
{% endif %}

still get 'failed'

{% if language.id() == 'en' %}
en
{% elseif language.id() == 'es-us' %}
es-us
{% elseif language.id() == 'en-us' %}
en-us
{% else %}
failed
{% endif %}

.... and, still, 'failed'.

get user's current language code in views

On Drupal 8.7.10

How can I get the user's current language code into views as a raw value, such as 'en' or 'fr-ca'.

This is not for filtering content. I need the raw value of the users' current language to pass into a url for a third-party tool.

I added a custom text field. Then placed in some twig code. The code is just failing to the fallback 'else' value.

Based on other forum posts, I've tried it these three ways:

{% if language.getId() == 'en' %}
en
{% elseif language.getId() == 'es-us' %}
es-us
{% elseif language.getId() == 'en-us' %}
en-us
{% else %}
failed
{% endif %}

I'm getting 'failed'

{% if language == 'en' %} 
en
{% elseif language == 'es-us' %}
es-us
{% elseif language == 'en-us' %}
en-us
{% else %}
failed
{% endif %}

still get 'failed'

{% if language.id() == 'en' %}
en
{% elseif language.id() == 'es-us' %}
es-us
{% elseif language.id() == 'en-us' %}
en-us
{% else %}
failed
{% endif %}

.... and, still, 'failed'.

Bumped by Community user
deleted 6 characters in body; edited title
Source Link
Pierre.Vriens
  • 36k
  • 40
  • 50
  • 182

How to get user's current language code in viewsViews?

On Drupal 8.7.10

How can I get the user's current language code into viewsViews as a raw value, such as 'en' or 'fr-ca'.?

This is not for filtering content. I need the raw value of the users' current language to pass into a url for a third-party tool.

I added a custom text field. Then placed in some twig code. The code is just failing to the fallback 'else' value.

Based on other forum posts, I've tried it these three ways:

{% if language.getId() == 'en' %}
en
{% elseif language.getId() == 'es-us' %}
es-us
{% elseif language.getId() == 'en-us' %}
en-us
{% else %}
failed
{% endif %}

I'm getting 'failed'

{% if language == 'en' %} 
en
{% elseif language == 'es-us' %}
es-us
{% elseif language == 'en-us' %}
en-us
{% else %}
failed
{% endif %}

still get 'failed'

{% if language.id() == 'en' %}
en
{% elseif language.id() == 'es-us' %}
es-us
{% elseif language.id() == 'en-us' %}
en-us
{% else %}
failed
{% endif %}

.... and, still, 'failed'.

get user's current language code in views

On Drupal 8.7.10

How can I get the user's current language code into views as a raw value, such as 'en' or 'fr-ca'.

This is not for filtering content. I need the raw value of the users' current language to pass into a url for a third-party tool.

I added a custom text field. Then placed in some twig code. The code is just failing to the fallback 'else' value.

Based on other forum posts, I've tried it these three ways:

{% if language.getId() == 'en' %}
en
{% elseif language.getId() == 'es-us' %}
es-us
{% elseif language.getId() == 'en-us' %}
en-us
{% else %}
failed
{% endif %}

I'm getting 'failed'

{% if language == 'en' %} 
en
{% elseif language == 'es-us' %}
es-us
{% elseif language == 'en-us' %}
en-us
{% else %}
failed
{% endif %}

still get 'failed'

{% if language.id() == 'en' %}
en
{% elseif language.id() == 'es-us' %}
es-us
{% elseif language.id() == 'en-us' %}
en-us
{% else %}
failed
{% endif %}

.... and, still, 'failed'.

How to get user's current language code in Views?

On Drupal 8.7.10

How can I get the user's current language code into Views as a raw value, such as 'en' or 'fr-ca'?

This is not for filtering content. I need the raw value of the users' current language to pass into a url for a third-party tool.

I added a custom text field. Then placed in some twig code. The code is just failing to the fallback 'else' value.

Based on other posts, I've tried it these three ways:

{% if language.getId() == 'en' %}
en
{% elseif language.getId() == 'es-us' %}
es-us
{% elseif language.getId() == 'en-us' %}
en-us
{% else %}
failed
{% endif %}

I'm getting 'failed'

{% if language == 'en' %} 
en
{% elseif language == 'es-us' %}
es-us
{% elseif language == 'en-us' %}
en-us
{% else %}
failed
{% endif %}

still get 'failed'

{% if language.id() == 'en' %}
en
{% elseif language.id() == 'es-us' %}
es-us
{% elseif language.id() == 'en-us' %}
en-us
{% else %}
failed
{% endif %}

.... and, still, 'failed'.

edited title
Link
turpentyne
  • 477
  • 4
  • 17
Loading
Source Link
turpentyne
  • 477
  • 4
  • 17
Loading