Is there a way to add unique static content (like a short heading and text) to just one specific dynamic page without it showing up on all the other dynamic pages? Can this be done using the CMS or editor, or would I need to use custom code?
Youād need custom code, but itās extremely simple
- In the CMS, have a boolean field, e.g.
showStatic - In the editor, add the static contents, preferably groups or within a strip for simplicity. Have it collapsed/hidden by default
Then in the dynamic page:
item = $w('#dynamicDataset').getCurrentItem()
if (item.showStatic) $w('#staticContent').expand() // or show()
That should take care of it
Thanks for your reply!
I canāt seem to make it work though. I have very little experience in code, especially Wix Studio, but Iāve tried to follow your steps. I would really appreciate if you had the time to tell me how to do it otherwise.
- Added a boolean field and named it āshowStaticā.
- Added a section with a paragraph inside on the dynamic page in the editor
- Made the section hidden by default
- Connected the paragraph to the boolean field in the CMS
- Added your code in the dynamic page
Is it because iāve connected it to the paragraph and not the section that makes it not work? And if I connect my paragraph to the CMS, I canāt have different content in the paragraph for other dynamic items. See screenshots below (Iāve made the section show for this example)
Thanks in advance!
The paragraph should not be connected to the boolean field, as itād simply turn into āTrueā or āFalseā instead of the text you want
As for the code:
- I forgot to define the
itemvariable.
In the first line of code, addconstbefore everything:
const item = $w('#dynamicDataset').getCurrentItem()
- You need to define the tag
#staticContentfor that section you want hidden/shown
Hovering over the red underlines in your code should provide you with hints about the cause of errors
Iāve now defined detached the paragraph from the CMS, added the item variable in the code and defined the tag ā still does not workā¦
Lines 3-4 in your code are unintelligible and may be crashing the code, remove them
Also, the code is running when the user enters the page, but the current item of the dataset is only present after it is loaded, so we should wait for that first:
$w('#dynamicDataset').onReady(() => {
const item = $w('#dynamicDataset').getCurrentItem()
if (item.showStatic) $w('#staticContent').show()
})
Thank you! Now it works like a charm. I misunderstood your definition of ācollapsed by defaultā, so I checked the box in the bottom right corner and now it works!
On the dynamic pages where this static section is shown, Iād like to hide the section above it. Should I create a new boolean field and set it up similarly, but modify the code from .expand to .collapse to control it via the dataset instead?
If thatās correct, how should I write the code for this?
No, itās based on the same boolean - If we go through the logic:
IF showStatic THEN expand the hidden static contents and collapse the normal dynamic content (Or however youād prefer to call those sections of course)
Now, Iām not sure what you meant about your misunderstanding of ācollapsed by defaultā, but Iāll describe them a little just in case, you can decide which one would suit your needs better
- Collapse eliminates the element from rendering on the page, which rearranges other items as if it was never there. It is reversed via expand.
- Hide still retains the space that the element wouldāve taken had it been rendered. And it is reversed via show.
Since youāre using sections, expand/collapse are probably the better method for you to use
$w('#dynamicDataset').onReady(() => {
const item = $w('#dynamicDataset').getCurrentItem()
if (item.showStatic) {
$w('#staticContent').expand()
$w('#dynamicContent').collapse()
}
})
The code block within the {} is executed if the statement in if (), i.e. the showStatic boolean, is true
Thatās perfect! Thank you so much for your help and for your explanations. I really appreciate it ![]()


