0

我正在尝试向电子邮件添加动态内容,并希望从电子邮件正文中删除速度语法,并使用如下 #set 指令将其替换为 $var:

#if('x' = 'y') #set($z = 'z') #elseif( 'a' = 'b') #set($c = 'c')

这是我的尝试:

 #if( {$date_opened_5ca62c21c455a} == "" && {$firstName} != "" )
 #set($header_greeting = "{$firstName}, Community Member.")
 #elseif( {$date_opened_5ca62c21c455a} != "" && {$firstName} != "" )
 #set( $header_greeting = "{$firstName}, member since 
 {$date_opened_5ca62c21c455a}")
 #else
 #set( $header_greeting = "Building Tomorrow Together" )
 #end

我收到一个错误,说应该关闭)

我还在黑暗中拍摄了一张照片:

 #set( $header_greeting = "#if( {$date_opened_5ca62c21c455a} == "" && {$firstName} != "" ){$firstName}, Community Member.#{elseif({$date_opened_5ca62c21c455a} != "" && {$firstName} != "")}{$firstName}, member since {$date_opened_5ca62c21c455a}#{else}Building Tomorrow Together#end" )
4

2 回答 2

0

您错过了正确的正式符号语法,它是:

${foo}

并不是

{$foo}

但作为旁注,您似乎不需要示例中的正式符号,因为它仅用于模棱两可的情况,也就是。$foo.bar反对${foo}.bar

此外,您的第一个示例使用=而不是==平等。

除此之外,您还必须验证缺失值是否为空字符串,而不仅仅是缺失值。如果缺少值,则$foo呈现为而不是空字符串。$foo要检查 null 或空,您可以使用静默符号:

#if("$!foo" == "") ...

有了所有这些评论,您的尝试可以重写为:

#if( "$!date_opened_5ca62c21c455a" == "" && "$!firstName" != "" )
  #set( $header_greeting = "$firstName, Community Member." )
#elseif( "$!date_opened_5ca62c21c455a" != "" && "$!firstName" != "" )
  #set( $header_greeting = "$firstName, member since $date_opened_5ca62c21c455a" )
#else
  #set( $header_greeting = "Building Tomorrow Together" )   
#end

最后但同样重要的是,如果为 null#if($foo)为空,则默认行为是返回 false ,因此您可以编写:$foo

#if( !$date_opened_5ca62c21c455a && $firstName )
  #set( $header_greeting = "$firstName, Community Member." )
#elseif( $date_opened_5ca62c21c455a && $firstName )
  #set( $header_greeting = "$firstName, member since $date_opened_5ca62c21c455a" )
#else
  #set( $header_greeting = "Building Tomorrow Together" )   
#end
于 2019-08-16T12:30:06.467 回答
0

这是使用 SharpSpring crm 中的速度脚本使用 set() 指令获取合并标签的解决方案。问题是在字符串内部使用合并标签,而不是与它连接。

#if( {$date_opened_5ca62c21c455a} == "" && {$firstName} != "" )

#set( $headerGreeting = {$firstName} + ", Community Member." )

#elseif( {$date_opened_5ca62c21c455a} != "" && {$firstName} != "" )

#set( $headerGreeting = {$firstName} + ", member since " + {$date_opened_5ca62c21c455a} )

#else

#set( $headerGreeting = "Building Tomorrow Together" )

#end
于 2019-08-19T15:27:28.483 回答