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.]
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
// 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
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?
The idea was:
if boolfield in CMS = True show “I´m positive”
else
show “”
endif
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:
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:
$w('#repeater').onItemReady(($item, data) => {
$item('#booleanText').text = data.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