Skip to main content
Level 2
mar 16, 2026 4:55 p. m. UTC
Resuelto

Hide an Image Placeholder where the image source url is an empty PMCF

I’m trying use velocity scripting to hide an Image placeholder when the Img Src is not populated. The Img Src that populated the image is referencing a PMCF Field. So IF the PMCF field is not generated via API, I want to be able to hide the image placeholder in Marketo is no longer visible when sent a sample.

I tried using the below but still fairly new to velocity script. If someone can help, it’d be much appreciated: 


 

#set( $imageUrl = ${member.PMCF_String02} ) 

#if( !$imageUrl || $imageUrl.trim() == "" ) 
## Do nothing (the section will be hidden) 
#else
<div><img height="auto" width="150" src="{{member.PMCF_String02}}"</div> 
#end

Este tema ha sido cerrado para respuestas.
SanfordWhiteman
User Group Leader
mar 16, 2026 6:22 p. m. UTC

Remember to use the Code option when inserting code so it’s readable.

 

trim() seems like overkill to me (why would there be only whitespace in this field, instead of nothing at all?). Either way, PMCFs are not nullable, so you don’t need to check for that case. Formal notation (curly braces) should only be used for output.

#set( $imageURL = $member.whateverField )
#if( !$imageURL.trim().isEmpty() )
<div><img src="${imageURL}"></div>
#end

 

1 respuesta

SanfordWhiteman
User Group Leader
User Group Leader
mar 16, 2026 6:22 p. m. UTC

Remember to use the Code option when inserting code so it’s readable.

 

trim() seems like overkill to me (why would there be only whitespace in this field, instead of nothing at all?). Either way, PMCFs are not nullable, so you don’t need to check for that case. Formal notation (curly braces) should only be used for output.

#set( $imageURL = $member.whateverField )
#if( !$imageURL.trim().isEmpty() )
<div><img src="${imageURL}"></div>
#end

 

Traducir