如果没有值,则删除电子邮件通知中的空格

时间:2017-01-25 06:41:05

标签: kentico

目前我正在使用一个电子邮件通知表单,我有大约二十位与会者。我使用这些值在电子邮件通知中显示。我的代码是:



{% AttendeeFirstName %} {% AttendeeLastName %}
{% AttendeeFirstName2 %} {% AttendeeLastName2 %}
{% AttendeeFirstName3 %} {% AttendeeLastName3 %}
{% AttendeeFirstName4 %} {% AttendeeLastName4 %}
{% AttendeeFirstName5 %} {% AttendeeLastName5 %}
{% AttendeeFirstName6 %} {% AttendeeLastName6 %}
{% AttendeeFirstName7 %} {% AttendeeLastName7 %}
{% AttendeeFirstName8 %} {% AttendeeLastName8 %}
{% AttendeeFirstName9 %} {% AttendeeLastName9 %}
{% AttendeeFirstName10 %} {% AttendeeLastName10 %}
{% AttendeeFirstName11 %} {% AttendeeLastName11 %}
{% AttendeeFirstName12 %} {% AttendeeLastName12 %}
{% AttendeeFirstName13 %} {% AttendeeLastName13 %}
{% AttendeeFirstName14 %} {% AttendeeLastName14 %}
{% AttendeeFirstName15 %} {% AttendeeLastName15 %}
{% AttendeeFirstName16 %} {% AttendeeLastName16 %}
{% AttendeeFirstName17 %} {% AttendeeLastName17 %}
{% AttendeeFirstName18 %} {% AttendeeLastName18 %}
{% AttendeeFirstName19 %} {% AttendeeLastName19 %}




在上面,如果有任何与会者出现价值,它的工作正常,但是这里有一个问题是,如果用户使用了两个与会者,那么两个与会者正在展示,但对于其他18个,它显示大的空白区域然后在那个任何字段之后使用即显示。 如果电子邮件通知中没有为该与会者提供任何值,我该如何删除此空格。



   In the below code i used as for loop but not getting the value.

 {% size = GroupSize;attName="";j=0;for(i=0; i < size; i++){if(j==0){attName+=AttendeeFirstName+ " "+AttendeeLastName}else if(j>0){
    attName+=AttendeeFirstName+j+ " "+AttendeeLastName+j}j+=1;}; attName#%}
&#13;
&#13;
&#13;

以下是使用rock建议的代码:

&#13;
&#13;
Additional Attendees:
{% att1 = AttendeeFirstName + " " + AttendeeLastName; if(att1 != " ") { return att1; } else { return ""; } #%}
{% att2 = AttendeeFirstName1 + " " + AttendeeLastName1; if(att2 != " ") { return att2; } else { return ""; } #%}
{% att3 = AttendeeFirstName2 + " " + AttendeeLastName2; if(att3 != " ") { return att3; } else { return ""; } #%}
{% att4 = AttendeeFirstName3 + " " + AttendeeLastName3; if(att4 != " ") { return att4; } else { return ""; } #%}
&#13;
&#13;
&#13;

在上面的代码中,如果我们仅使用FirstName,那么对于其他代码,电子邮件通知中会有一些空间。

1 个答案:

答案 0 :(得分:5)

我猜大空格是由括号之间的空格引起的:%} {%

建议编号1:您不必使用单独的代码块。

{% AttendeeFirstName + " " + AttendeeLastName %}

建议编号2:使用条件。

{% 
list = "";
br = "<br />";
att1 = AttendeeFirstName + " " + AttendeeLastName; if(att1 != " ") { list += att1+br; }  
att2 = AttendeeFirstName1 + " " + AttendeeLastName1; if(att2 != " ") { list += att2+br; }   
att3 = AttendeeFirstName2 + " " + AttendeeLastName2; if(att3 != " ") { list += att3+br; }  
att4 = AttendeeFirstName3 + " " + AttendeeLastName3; if(att4 != " ") { list += att4; }  
return list; #%}

建议编号3:使用循环。我不知道你如何存储你的数据,但是迭代一个集合而不是硬编码所有二十个参与者会更加清晰。

建议编号4:查看宏语法文档,尤其是conditionsloops