Hi guys!
I am creating articles for my website using a database and dynamic pages. On my dynamic page I have used some text and images to create different paragraphs:
![](https://static.wixstatic.com/media/a27d24_a427cc7e29b644b6a25da499983a8edc~mv2.png/v1/fill/w_59,h_53,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/a27d24_a427cc7e29b644b6a25da499983a8edc~mv2.png)
In some articles there is no image between paragraph1 and paragraph2; in that case there is huge white gap between these paragraphs (because the image-element has no value). I am wondering if it is possible using code to hide this element if their is no image to show.
I am not able to make this work, the problem is same. If i have an image display it if its NULL then just collapse but nothing seems to be working.
Hello Greg and Marina, i used the above code samples and the tutorial link sames. but my image is collapsing on every page now even if the field has an image.
has anyone resolved this with a working code sample?
please help. thank you
Hey guys! If someone still struggling with this issue... The link below worked perfect for me:
https://support.wix.com/en/article/how-to-hide-a-video-player-when-there-is-no-video-to-play
This code works for me but only on the first item in the dataset. If I include a "console.log" statement where the show and hide lines are, I can see it is only logging once. Should it work for all returned items or is there different code for this scenario?
Actually I've fixed the original problem – I was naming the dataset wrong. But not I have the opposite problem. The video and title text "Video" both collapse even when there is a video in the dataset.
$w.onReady( () => {
$w("#dataset1").onReady( () => {
let item = $w("#dataset1").getCurrentItem();
if (item.Video) {
$w("#video1").show();
} else {
$w("#video1").collapse();
$w("#video1").hide();
}
} );
} );
$w.onReady( () => {
$w("#dataset1").onReady( () => {
let item = $w("#dataset1").getCurrentItem();
if (item.Video) {
$w("#text27").show();
} else {
$w("#text27").collapse();
$w("#text27").hide();
}
} );
} );
Thank you Tal! The address is nawayaegypt.org/hub/casestudies/cases (it's a dynamic page called Case Studies Cases (title)) – it is not live yet though, do I need to publish it so you can see it?
Hi Brendon,
Can you please send us the site URL and the name of the page so that we can have a look?
Thanks,
Tal.
I am trying to do the same, but with a video. I am a bit stuck, in one of my datasets that doesn't have a link to any video, the video still shows up on the page. What am I doing wrong?
#CaseStudies dataset is the name of my dataset
#video1 is the element on the dynamic page
Here is the code I am attempting:
$w.onReady( () => {
$w("#CaseStudies dataset").onReady( () => {
let item = $w("#CaseStudies dataset").getCurrentItem();
if (item.Video) {
$w("#video1").show();
} else {
$w("#video1").collapse();
$w("#video1").hide();
}
} );
} );
Hi,
This should work. Should the issue persists, please clarify what is the scenario (to make sure that it is the same one as "vanmaaren" ) and send us the site URL so that we can have a look.
Tal.
Same issue on my site - has this info worked for you? I'm trying to follow along to fix my own layout, but this is my first coding experience so I am struggling to understand some of the instructions in the tutorials.
Do like this
$w.onReady( () => {
$w("#myDataset").onReady( () => {
let item = $w("#myDataset").getCurrentItem();
if (item.image) {
$w("#imageElement").show();
} else {
$w("#imageElement").collapse();
$w("#imageElement").hide();
}
} );
} );
Great! Thanks for your answer. I am wondering how to check if the image is present;
$w.onReady( () => {
$w("#myDataset").onReady( () => {
$w("#myDataset").getCurrentItem().image => {
IF (null) {
$w("#image1").collapse() ; }
ELSE () {
$w("#image1").show(); }
}
} ) }
Something like this if 'image' is the fieldname and image1 the objectname?
Just throw in a if statement on your on ready function to check if the image is present. If not use the collapse() method on the image object and it will collapse the white area.
The dynamic page have a dataset so read in the API about the dataset and the method onReady on the dataset. You must put the if within the pages onready and as well within the datasets onready to make sure the dataset and image are loaded before you check.
Good luck.