I am trying to figure out if there is a way to conditionally hide the mediainfos section of a popuptemplate?
The photos are external (not attachments) and I have a column called PHOTOS that will say 0, 1 or 2. Ideally I would like the mediainfos section not show if 0 appears in the PHOTOS attribute but so far nothing I have tried is working.
Does anyone have any insight into how this might be accomplished if it is even possible?
I'd like to avoid the broken image icon, like in the screenshot below so folks don't think that it's not working.
Solved! Go to Solution.
Hi there,
You can do this with the use of Function, Promise or with use of Arcade expressions. This SDK sample shows how to change the popupTemplate's content dynamically depending on feature attributes. I have modified this sample just a little bit to show images depending on feature attributes. The main logic is in populationChange function.
Simple app: https://codepen.io/U_B_U/pen/dyVEWya?editors=1000
Hope this helps.
Hi there,
You can do this with the use of Function, Promise or with use of Arcade expressions. This SDK sample shows how to change the popupTemplate's content dynamically depending on feature attributes. I have modified this sample just a little bit to show images depending on feature attributes. The main logic is in populationChange function.
Simple app: https://codepen.io/U_B_U/pen/dyVEWya?editors=1000
Hope this helps.
@UndralBatsukh thank you so much for the visual - this was extremely helpful and with some tweaking I was able to accomplish what I needed! I appreciate the help
Could you not use an if statement? If the value of 0 is returned use this template that doesn't include mediainfo, else use this other template that includes mediainfo.
I guess I had an additional question - with the function to handle the photos, is it possible to combine both the fieldInfos and the content created by the function. I'd like to display the actual attribute data for the records with the photos at the bottom but the fieldInfos does not appear.
Yep you sure can. Just add a FieldsContent to your popupTemplate's content.
I updated the codepen app for you to showcase this: https://codepen.io/U_B_U/pen/dyVEWya?editors=1000
I thought that may have been the way to go about this but I wasn't sure! Thank you!
Is there a way to check if the image exists before adding it to the mediaInfos? I have been trying it, but I think it needs to work asynchronously, and I'm not sure how to get it work. My images files match an id in the attributes, but not all features have an image.
@chuckfrank - That I am not sure of - we have a "Photo" column that records the number of photographs that were submitted with the record (0-2) so I have in my code some lines where depending on the photo count, it will display the one photo, two photos or "No photos" text. We also store the photos outside of AGO and their file names match the objectID of the record.