# How i can check variable for non-empty in selector?

**URL:** <https://discourse.mozilla.org/t/how-i-can-check-variable-for-non-empty-in-selector/90181>\
**Category:** Fluent\
**Tags:** learning, issue\
**Created:** [December 13, 2021, 5:40pm UTC](https://discourse.mozilla.org/t/how-i-can-check-variable-for-non-empty-in-selector/90181 "2021-12-13T17:40:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DenF](https://avatars.discourse-cdn.com/v4/letter/d/b5a626/32.png) [@DenF](https://discourse.mozilla.org/u/DenF)\
**Post date:** [December 13, 2021, 5:40pm UTC](https://discourse.mozilla.org/t/how-i-can-check-variable-for-non-empty-in-selector/90181/1 "2021-12-13T17:40:39Z")

</div>

How i can check random $variable for non-empty/existing?  
What about if variable will not passed from application?

For example, random .ftl file:

```
that_string = 
{ $username ->
          [what i need to pass there?] Hello! ### - if $username is empty
        *[other] Hello, { $username }!
}.

```

I need to check $username for existance inside FTL syntax.  
How it’s possible?

---

<div class="post-metadata">

**Author:** ![zbraniecki](https://avatars.discourse-cdn.com/v4/letter/z/97f17d/32.png) [@zbraniecki](https://discourse.mozilla.org/u/zbraniecki)\
**Post date:** [December 13, 2021, 9:52pm UTC](https://discourse.mozilla.org/t/how-i-can-check-variable-for-non-empty-in-selector/90181/2 "2021-12-13T21:52:04Z")

</div>

Fluent selection is not meant to replace code logic.  
You should check if the user name is present and decide on what l10n message to use to localize it.  
You should have two messages `hello-not-logged-in` and `hello-logged-in` and the latter should take a variable.

See [https://github.com/projectfluent/fluent/wiki/Good-Practices-for-Developers](https://github.com/projectfluent/fluent/wiki/Good-Practices-for-Developers) for more details.

---

<div class="post-metadata">

**Author:** ![ChristineWood](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/christinewood/32/71778_2.png) [@ChristineWood](https://discourse.mozilla.org/u/ChristineWood)\
**Post date:** [January 3, 2026, 9:37pm UTC](https://discourse.mozilla.org/t/how-i-can-check-variable-for-non-empty-in-selector/90181/3 "2026-01-03T21:37:20Z")

</div>

You can handle this kind of situation in a few different ways depending on how your template is structured. Usually, the idea is to check whether the variable is present and then display a fallback text if it isn’t. Fluent provides some basic patterns for handling missing or empty values, so you don’t always need to rely on complex logic. You can use a simple default approach or let the message choose the correct variant when the variable isn’t passed. This way your template stays clean, and it still works even if the application doesn’t provide the variable.
