2016-09-06 68 views
2

我通過data = level media獲取滑塊的圖像:-1,slide 在新聞單頁上,我想使用新聞圖像而不是。所以我把這個代碼放在[globalVar = GP:tx_news_pi1|news > 0]的條件下,得到新聞的圖片。一切都好。但是,如果沒有新聞形象,我想展示關卡媒體。我怎樣才能做到這一點?用回退替代文件references.data

這裏的Typo腳本:

lib.keyVisual = COA 
lib.keyVisual { 
    10 = FILES 
    10 { 
     references { 
      data = levelmedia:-1,slide 
     } 

     renderObj = COA 
     renderObj.10 = IMAGE 
     renderObj.10 { 
      file { 
       import.data = file:current:uid 
       treatIdAsReference = 1 
       width = {$keyVisualWidth} 
       #width.field > 
       height = {$keyVisualHeight} 

      } 
     } 

     renderObj.20 = COA 
     renderObj.20 { 
      1 = TEXT 
      1 { 
       data = file:current:title 
       required = 1 
       wrap = <h3>|</h3> 
      } 
      2 = TEXT 
      2 { 
       data = file:current:description 
       required = 1 
       wrap = <p>|</p> 
      } 
      stdWrap.wrap = <div class="imageCaptionBox">|</div> 
      stdWrap.required = 1 
     } 

     renderObj.wrap = <li>|</li> 
    } 
    wrap = <section id="keyvisual" class="keyvisual fullWidth"><ul class="slider nav">|</ul></section> 
} 
[globalVar = GP:tx_news_pi1|news > 0] 
    lib.keyVisual { 
     10 { 
      references { 
       data > 
       table = tx_news_domain_model_news 
       uid.data = GP:tx_news_pi1|news 
       fieldName = fal_media 
      } 

      # only images with showinpreview 
      renderObj.if { 
       value = 1 
       equals.data = file:current:showinpreview 
      } 
     } 
    } 
[global] 

回答

1

使用ifEmpty stdWrap選項。

如果您的COA爲空,您可以使用此選項呈現默認圖像。

簡單的例子來說明一下:

[globalVar = GP:tx_news_pi1|news > 0] 
    lib.keyVisual { 
    stdWrap.ifEmpty.cObject < .10 

    #overrides for news picture 
    10 { 
     ... 
    } 
    } 
[global] 
+0

10.stdWrap.ifEmpty.cObject <0.10會爲我做! –

1

所有條件有[else]所以你不需要重新定義。

[globalVar = GP:tx_news_pi1|news > 0] 
lib.keyVisual { 
    ... from news... 
} 
[else] 
lib.keyVisual { 
    ... from levelmedia ... 
} 
[global] 

然後您需要區分圖像是否適用於新聞。

[globalVar = GP:tx_news_pi1|news > 0] 
lib.keyVisual = COA 
lib.keyVisual { 
    10 = CONTENT 
    10 { 
     // get news record and then get file 
     ... from news... 
     if.empty.field = media 
    } 
    20 = FILES 
    20 { 
     ... from levelmedia ... 
     if { 
      empty.field = media 
      negate = 1 
     } 
    } 
} 
[else] 
lib.keyVisual { 
    ... from levelmedia ... 
} 
[global] 

可以通過使用複製的levelmedia用法的臨時對象進行優化。

temp.levelmediaImage { 
    ... 
} 
[globalVar = GP:tx_news_pi1|news > 0] 
kib.keyVisual = COA 
lib.keyVisual { 
    10 = CONTENT 
    10 { 
     // get news record and then get file 
     ... from news... 
     if.empty.field = media 
    } 
    20 < temp.levelmediaImage 
    20 { 
     if { 
      empty.field = media 
      negate = 1 
     } 
    } 
} 
[else] 
lib.keyVisual < temp.levelmediaImage 
[global]