Conditionally display mediainfo photo in popuptemplate based on an attribute value

1247
10
Jump to solution
01-18-2022 11:30 AM
luckachi
Occasional Contributor III

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.

luckachi_0-1642534182978.png

 

0 Kudos
1 Solution

Accepted Solutions
UndralBatsukh
Esri Regular Contributor

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.

 

View solution in original post

10 Replies
UndralBatsukh
Esri Regular Contributor

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.

 

luckachi
Occasional Contributor III

@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 

0 Kudos
MatthewDriscoll
MVP Alum

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.

0 Kudos
luckachi
Occasional Contributor III

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.

0 Kudos
UndralBatsukh
Esri Regular Contributor

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

 

luckachi
Occasional Contributor III

I thought that may have been the way to go about this but I wasn't sure! Thank you!

0 Kudos
chuckfrank
Occasional Contributor

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.

0 Kudos
luckachi
Occasional Contributor III

@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.

0 Kudos
chuckfrank
Occasional Contributor
Thanks, for now I'm using the "altText" and displaying a message when there's not a photo. Maybe in a future version there will be other ways to handle the variable number of media infos.



Thanks


0 Kudos