Kentico 10 转换参考
Kentico 10 Transformation Reference
我正在尝试动态显示数据(如果它不为空),如果该项目没有数据,则将 header 设置为空。
下面是我的转换代码。我试图隐藏任何没有数据的 h5 标题。
例如,如果我的 CurrentDocument.EVAl("Client") 返回为空,我想隐藏整个 class "client-heading"。我认为这与
!IfEmpty.
<div class="left-data small-6 medium-3 large-3 columns">
<div class="location-heading">
<h5 class="data-heading">Location:</h5>
<h5>{% CurrentDocument.GetValue("City") #%}, {% CurrentDocument.GetValue("State") #%}</h5>
</div>
<div class="client-heading">
<h5 class="data-heading">Client:</h5>
<h5>{% CurrentDocument.EVAL("Client") #%}</h5>
</div>
<div class="year-heading">
<h5 class="data-heading">Year Completed:</h5>
<h5>{% CurrentDocument.GetValue("yearCompleted") #%}</h5>
</div>
看起来像这样:
{% if(Client != "") { %}
<div class="client-heading">
<h5 class="data-heading">Client:</h5>
<h5>{% Client %}</h5>
</div>
{% } %}
还知道您的转换结合了 ASCX 和宏转换方法。可能要确保你把它清理干净。
我要问的第一个快速问题是您引用的 "CurrentDocument" 不是转换后的对象,它是实际的当前文档。所以如果你想得到转换对象的City值,你应该使用{% City %}
而不是{% CurrentDocument.GetValue("City") %}
至于测试是否为 null 或空,如果是字符串,只需使用
{% string.IsNullOrWhiteSpace(TheValue) ? "It's null" : "It's not null" %}
或
{% if(string.IsNullOrWhiteSpace(TheValue)) { %}
It's null
{% } %}
{% if(!string.IsNullOrWhiteSpace(TheValue)) { %}
It's not null
{% } %}
或具体到您的转型:
<div class="left-data small-6 medium-3 large-3 columns">
{% if(!string.isnullorwhitespace(CurrentDocument.GetValue("City")) { %}
<div class="location-heading">
<h5 class="data-heading">Location:</h5>
<h5>{% CurrentDocument.GetValue("City") #%}
{% !string.isnullorwhitespace(CurrentDocument.GetValue("State")) ? ","+CurrentDocument.GetValue("State") : "" #%}</h5>
</div>
{% } %}
{% if(!string.isnullorwhitespace(CurrentDocument.GetValue("Client")) { %}
<div class="client-heading">
<h5 class="data-heading">Client:</h5>
<h5>{% CurrentDocument.GetValue("Client") #%}</h5>
</div>
{% } %}
{% if(!string.isnullorwhitespace(CurrentDocument.GetValue("yearCompleted")) { %}
<div class="year-heading">
<h5 class="data-heading">Year Completed:</h5>
<h5>{% CurrentDocument.GetValue("yearCompleted") #%}</h5>
</div>
{% } %}
请记住,如果 div 上的值为 null 或白色 space,另一种选择是仅添加一个隐藏的 CSS,因此它呈现 HTML 但是用户看不到它。
我正在尝试动态显示数据(如果它不为空),如果该项目没有数据,则将 header 设置为空。
下面是我的转换代码。我试图隐藏任何没有数据的 h5 标题。
例如,如果我的 CurrentDocument.EVAl("Client") 返回为空,我想隐藏整个 class "client-heading"。我认为这与 !IfEmpty.
<div class="left-data small-6 medium-3 large-3 columns">
<div class="location-heading">
<h5 class="data-heading">Location:</h5>
<h5>{% CurrentDocument.GetValue("City") #%}, {% CurrentDocument.GetValue("State") #%}</h5>
</div>
<div class="client-heading">
<h5 class="data-heading">Client:</h5>
<h5>{% CurrentDocument.EVAL("Client") #%}</h5>
</div>
<div class="year-heading">
<h5 class="data-heading">Year Completed:</h5>
<h5>{% CurrentDocument.GetValue("yearCompleted") #%}</h5>
</div>
看起来像这样:
{% if(Client != "") { %}
<div class="client-heading">
<h5 class="data-heading">Client:</h5>
<h5>{% Client %}</h5>
</div>
{% } %}
还知道您的转换结合了 ASCX 和宏转换方法。可能要确保你把它清理干净。
我要问的第一个快速问题是您引用的 "CurrentDocument" 不是转换后的对象,它是实际的当前文档。所以如果你想得到转换对象的City值,你应该使用{% City %}
而不是{% CurrentDocument.GetValue("City") %}
至于测试是否为 null 或空,如果是字符串,只需使用
{% string.IsNullOrWhiteSpace(TheValue) ? "It's null" : "It's not null" %}
或
{% if(string.IsNullOrWhiteSpace(TheValue)) { %}
It's null
{% } %}
{% if(!string.IsNullOrWhiteSpace(TheValue)) { %}
It's not null
{% } %}
或具体到您的转型:
<div class="left-data small-6 medium-3 large-3 columns">
{% if(!string.isnullorwhitespace(CurrentDocument.GetValue("City")) { %}
<div class="location-heading">
<h5 class="data-heading">Location:</h5>
<h5>{% CurrentDocument.GetValue("City") #%}
{% !string.isnullorwhitespace(CurrentDocument.GetValue("State")) ? ","+CurrentDocument.GetValue("State") : "" #%}</h5>
</div>
{% } %}
{% if(!string.isnullorwhitespace(CurrentDocument.GetValue("Client")) { %}
<div class="client-heading">
<h5 class="data-heading">Client:</h5>
<h5>{% CurrentDocument.GetValue("Client") #%}</h5>
</div>
{% } %}
{% if(!string.isnullorwhitespace(CurrentDocument.GetValue("yearCompleted")) { %}
<div class="year-heading">
<h5 class="data-heading">Year Completed:</h5>
<h5>{% CurrentDocument.GetValue("yearCompleted") #%}</h5>
</div>
{% } %}
请记住,如果 div 上的值为 null 或白色 space,另一种选择是仅添加一个隐藏的 CSS,因此它呈现 HTML 但是用户看不到它。