【问题标题】:Kentico 10 Transformation ReferenceKentico 10 转换参考
【发布时间】:2018-04-22 16:23:27
【问题描述】:

如果数据不为空,我会尝试动态显示数据,如果该项目没有数据,则将标题设置为空。

以下是我的转换代码。我正在尝试隐藏任何没有数据的 h5 标题。

例如,如果我的 CurrentDocument.EVAl("Client") 返回为空,我想隐藏整个类“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>

【问题讨论】:

    标签: transformation kentico


    【解决方案1】:

    看起来像这样:

    {% if(Client != "") { %}  
    <div class="client-heading">
        <h5 class="data-heading">Client:</h5>
        <h5>{% Client %}</h5>
    </div>
    {% } %}
    

    还知道您的转换结合了 ASCX 和宏转换方法。可能要确保你清理它。

    【讨论】:

    • 我会试一试。我将研究 ASCX 和宏转换方法
    【解决方案2】:

    我要问的第一个快速问题是您引用的不是转换后的对象的“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 或空白时仅添加隐藏的 CSS,以便呈现 HTML 但用户看不到它。

    【讨论】:

    • 感谢您提供的所有精彩信息。出于某种原因,上面的代码对我不起作用。它只是无法执行,我渲染的代码是这样的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多