2017-11-09 9 views
1

データが空でない場合は動的に表示し、その項目のデータがない場合はヘッダーを空に設定しようとしています。Kentico 10変換リファレンス

以下は私の変換コードです。私は、データを持たないh5見出しを隠そうとしています。

たとえば、CurrentDocument.EVAl( "Client")が空に戻った場合、クラス全体を非表示にしたいと思います。私はそれが と何か関係があると仮定します!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> 

答えて

2

それはこのようになります:

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

はまた、あなたの変換がASCXとマクロの変換方法の両方を組み合わせている知っています。これをきれいにすることを確認したいかもしれません。

+0

私はこれを撮影します。私はASCXとマクロの変換方法を調べます –

+0

これは完全に機能しました! –

0

最初の簡単な質問は、あなたが変換されたオブジェクトではない「CurrentDocument」を参照していることです。実際の現在のドキュメントです。あなたが変換されたオブジェクトの街値を取得したいのであれば、あなたは何かがnullまたは空の場合、それは文字列だ場合、単に

{% string.IsNullOrWhiteSpace(TheValue) ? "It's null" : "It's not null" %} 

かを使用するテスト用として{% CurrentDocument.GetValue("City") %}

の代わりに​​を使用する必要がありますあなたの転換へ

{% if(string.IsNullOrWhiteSpace(TheValue)) { %} 
    It's null 
{% } %} 
{% if(!string.IsNullOrWhiteSpace(TheValue)) { %} 
    It's not null 
{% } %} 

またはspecificaly:

<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> 
{% } %} 

別の方法として、値がnullまたはdivの空白の場合はHTMLをレンダリングするが、ユーザーは表示しないようにするには、非表示のCSSを追加することです。

+0

すべての素晴らしい情報をありがとう。なんらかの理由で、上記のコードは私のためには機能しません。それは単に実行に失敗し、私のレンダリングされたコードはこのように出てくる。

関連する問題