2017-11-09 9 views
1

데이터가 비어 있지 않으면 동적으로 표시하려고하고 해당 항목에 대한 데이터가없는 경우 헤더를 비어있게 설정하려고합니다.Kentico 10 변환 참조

다음은 나의 변환 코드입니다. 데이터가없는 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> 

답변

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") %}

{% 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의 공백 인 경우 숨겨진 CSS를 추가하여 HTML을 렌더링하지만 사용자가 볼 수 없도록하는 것입니다.

+0

모든 멋진 정보를 제공해 주셔서 감사합니다. 웬일인지, 위의 코드는 나를 위해 작동하지 않습니다. 그것은 단지 실행에 실패하고 렌더링 된 코드는 이와 같이 나옵니다.

관련 문제