# IF / THEN for an Expression in combination with CMS

**URL:** <https://forum.wixstudio.com/t/if-then-for-an-expression-in-combination-with-cms/69866>\
**Category:** Ask the community\
**Tags:** code, question, cms, wix\
**Created:** [March 25, 2025, 9:02am UTC](https://forum.wixstudio.com/t/if-then-for-an-expression-in-combination-with-cms/69866 "2025-03-25T09:02:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![user5423](https://avatars.discourse-cdn.com/v4/letter/u/f17d59/32.png) [@user5423](https://forum.wixstudio.com/u/user5423)\
**Post date:** [March 25, 2025, 9:02am UTC](https://forum.wixstudio.com/t/if-then-for-an-expression-in-combination-with-cms/69866/1 "2025-03-25T09:02:54Z")

</div>

Hi everybody,

I fear this is a beginners question… As a former Xojo Programmer I´m trying to fix a simple thing. So here is my question

There is a dynamic Item Site in which I have different CMS values in fields. No problem so far. But - I dont want to have the normal boolean expression. Instead I´m trying to replace an expression with “yes” or “no” depending on the bool value in the CMS.

I´m missing each idea where to put the code and how the code ist targeting that expression field.

Help would be nice. Thanks, Chrisitan

**Product:**  
[Which editor or feature is your question most relevant to? e.g. Wix Editor, Wix Studio Editor.]

**What are you trying to achieve:**  
[Explain the details of what you are trying to achieve. The more details you provide, the easier it is to understand what you need.]

**What have you already tried:**  
[Share resources, forum topics, articles, or tutorials you’ve already used to try and answer your question.]

**Additional information:**  
[Include any other pertinent details or information that might be helpful for people to know when trying to answer your question.]

---

<div class="post-metadata">

**Author:** ![DeanAyalon](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/deanayalon/32/94633_2.png) [@DeanAyalon](https://forum.wixstudio.com/u/DeanAyalon)\
**Post date:** [March 25, 2025, 10:09am UTC](https://forum.wixstudio.com/t/if-then-for-an-expression-in-combination-with-cms/69866/2 "2025-03-25T10:09:57Z")

</div>

I don’t think CMS Expressions has conditional logic

However, storing the word ‘yes’/‘no’ in a separate field in the CMS has no real added value - Instead, you can just have it shown that way on the clientside

Such as

```js
// let item be the CMS item
$w('#booleanText').text = item.boolField ? 'Yes' : 'No'

```

This takes milliseconds for the visitor, and no extra computation or storage from Wix’s servers

---

<div class="post-metadata">

**Author:** ![user5423](https://avatars.discourse-cdn.com/v4/letter/u/f17d59/32.png) [@user5423](https://forum.wixstudio.com/u/user5423)\
**Post date:** [March 25, 2025, 1:21pm UTC](https://forum.wixstudio.com/t/if-then-for-an-expression-in-combination-with-cms/69866/3 "2025-03-25T13:21:41Z")

</div>

Thanks for your answer. Nono I didn´t want to store yes / no. I wanted to store any word in an expression dependig on the bool status.

Thanks for the code, but where to store? Inside the $w area?

---

<div class="post-metadata">

**Author:** ![user5423](https://avatars.discourse-cdn.com/v4/letter/u/f17d59/32.png) [@user5423](https://forum.wixstudio.com/u/user5423)\
**Post date:** [March 25, 2025, 1:25pm UTC](https://forum.wixstudio.com/t/if-then-for-an-expression-in-combination-with-cms/69866/4 "2025-03-25T13:25:54Z")

</div>

The idea was:  
if boolfield in CMS = True show “I´m positive”  
else  
show “”  
endif

---

<div class="post-metadata">

**Author:** ![DeanAyalon](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/deanayalon/32/94633_2.png) [@DeanAyalon](https://forum.wixstudio.com/u/DeanAyalon)\
**Post date:** [March 25, 2025, 1:32pm UTC](https://forum.wixstudio.com/t/if-then-for-an-expression-in-combination-with-cms/69866/5 "2025-03-25T13:32:12Z")

</div>

I see, then the wording confused me a bit, I thought you were asking about CMS Expressions

So the code I have given you is exactly the functionality you were thinking of

Where to put it depends on how you’re displaying the CMS item

If this is a dynamic page which belongs to the CMS item, then you need to retrieve it from the dynamic dataset:

```js
const dataset = $w('#dynamicDataset')
dataset.onReady(() => {
    const item = dataset.getCurrentItem()
    $w('#booleanText').text = item.booleanField ? 'Yes' : 'No'
})

```

If you’re using a Repeater to display multiple CMS items:

```js
$w('#repeater').onItemReady(($item, data) => {
    $item('#booleanText').text = data.booleanField ? 'Yes' : 'No'
})

```

---

<div class="post-metadata">

**Author:** ![user5423](https://avatars.discourse-cdn.com/v4/letter/u/f17d59/32.png) [@user5423](https://forum.wixstudio.com/u/user5423)\
**Post date:** [March 25, 2025, 1:36pm UTC](https://forum.wixstudio.com/t/if-then-for-an-expression-in-combination-with-cms/69866/6 "2025-03-25T13:36:11Z")

</div>

> [@DeanAyalon](#):
>
> ```javascript
> const dataset = $w('#dynamicDataset')
> dataset.onReady(() => {
> const item = dataset.getCurrentItem()
> $w('#booleanText').text = item.booleanField ? 'Yes' : 'No'
> })
> 
> ```

Ahhh that´s it. Thank you very much. I need it in displaying CMS data an it works directly after replacing the specific variables. Thanks!!

Christian
