Is there a way of making specific sections appear on dynamic pages?

I’m having trouble with
This sort of follows on from a previous thread asking a different question, but is related to the outcome I’d like to achieve. I wanted to ask whether anyone may know a way of setting up a dynamic page in such a way that a section featuring static/non-dynamic content could be displayed on a single page, but not another.

Working in
Wix Editor plus the CMS.

Site link
First Page: https://www.patvarchive.co.uk/narrativecms/greataction
Second Page: https://www.patvarchive.co.uk/narrativecms/greatmystery

What I’m trying to do
How I’ve set up the page(s) relates to this existing thread: Add static, unique, content to a single dynamic page - #6 by Lukas_Gook

As you may be able to interpret from my two Site links, the top image and the two text fields are connected to CMS (that’s all okay, no problem there), you may also see the two sections below, the ones I’ve differentiated with red and yellow backgrounds, both of these sections contain static content within the dynamic page template, the outcome I have in mind is that the red section, that features content relating to Great! Action would ONLY appear on that page, with the same applying to the yellow section on the Great! Mystery page.
Is this at all possible to do?

I know that I’m trying to make non-dynamic content appear on a dynamic page, which you may think defeats the point of a dynamic page, but I need to be able to display the various YouTube playlists within the tabs, and you can’t connect those to the CMS, but I’m equally at a point where if I was to keep using static pages* I’d easily hit the 100 page limit.

*(Two static page examples: https://www.patvarchive.co.uk/channels/bbc/bbcone
https://www.patvarchive.co.uk/channels/bbc/bbctwo
of which I’ve already used up 50 static pages)

What I’ve tried so far
My original thread was about trying to somehow make the YouTube playlists somehow connect to the CMS, but I think nothing would work for that. So the other thread I’ve linked above (Lukas_Gook) gives me a small glimmer of hope that some sort of code may work. (I’m not really clued up on code, but I’m willing to try!)

If anyone is able to provide any sort of help or advice then it would be very greatfully received, thank you for reading

1 Like

Sounds possible. Similar to the linked post, you’ll want to:

  • Add a boolean field to your CMS. Something like showStatic
  • Then use code similar to:

Whereby, you’ll update the ids of the elements for your use case.

When the boolean is true, the static content will show and dynamic collapse, and the opposite for false

1 Like

Thank you. I tweaked it slightly so that my sections are collapsed by default and expand when on the relevant pages, but I’ve got a working solution, so thank you. I’ve changed my SEO settings for that page so those existing links won’t now work, so here’s the two updated links showing the code working…

Out of curiosity… just because I don’t really know code (though I do understand how what you suggested is working) and just because it may be able to help make the process slightly easier if it is possible, is there any way of instead of using booleans, to instead have it check the Title item in the CMS, and if it matches the specific text then it acts the same as a true boolean?
For example something like
if (item.title = “Great! Action”)
… or am I just overcomplicating things and should just work with what I’ve got?

Thanks again!

Absolutely possible. And you almost got it too.

If this is your current code:

$w('#dynamicDataset').onReady(() => {
    const item = $w('#dynamicDataset').getCurrentItem()
   
    if (item.showGreatAction) {
        $w('#sectionGreatAction').expand()
    }

    if (item.showGreatMystery) {
        $w('#sectionGreatMystery').expand()
    }

})

Simply replace it with:

$w('#dynamicDataset').onReady(() => {
    const item = $w('#dynamicDataset').getCurrentItem()
   
    if (item.title == "ABC") {
        $w('#sectionGreatAction').expand()
    }

    if (item.title == "XYZ") {
        $w('#sectionGreatMystery').expand()
    }

})

And you can copy paste the if then block as much as you want.

1 Like

Thank you, tried it out and it’s working. That way certainly makes it easier for me, as you may have noticed from the boolean code that my way around it was to essentially make a new boolean for each page, which would have been fine, but would just require a little more work making sure the right true values were selected.

Thanks again to you both.

2 Likes

I know the matter is closed, but to comment on that question
Yes, but I wouldn’t hard-code something this specific

1 Like