在typoscript中的后备图像

时间:2015-05-21 15:56:49

标签: typo3 typoscript

我有以下菜单类型,它适用于主要部分。 但是,如果没有找到图像,我想添加一个后备图像。

  tt_content.menu {
  20 {
    108 = HMENU
    108 {
      special = directory
      special.value.field = pages
      1 = TMENU
      1.wrap = <div class="special_menu">|</div>
      1.NO {
        doNotLinkIt = 1
        stdWrap.cObject = COA
        stdWrap.cObject {
          10 = FILES
          10 {
            references {
                table = pages
                fieldName = media
            }
            renderObj = IMAGE
            renderObj {
                file {
                    width = 263c
                    height = 155c
                    maxW = 263c
                    maxH = 155c
                    import.data = file:current:publicUrl
                    # if file:current:publicUrl is empty, use default image
                    if.isFalse = fileadmin/my/path/to/image.jpg
                }

            altText.field = title
            imageLinkWrap = 1
            imageLinkWrap {
                enable = 1
                typolink.parameter.field = uid
                }
            }
            stdWrap.wrap = <div class="menu10_bild">|</div>
          }

          20 = TEXT
          20.field = title
          20.typolink.parameter.field = uid
          20.wrap = <div class="menu10_text">|

          30 = TEXT
          30.field = abstract
          30.wrap = <p>|</p></div><div class="w-clearfix">&nbsp;</div>
        }
      }
    }    
  }
}

由于某种原因,它只是忽略了这一行。有人可以帮我吗?

2 个答案:

答案 0 :(得分:1)

您应该查看TypoScript Reference stdWrap.ifEmpty 在您的情况下,代码应该如下所示

tt_content.menu {
    20 {
        108 {
            1.NO {
                stdWrap.cObject {
                    10 = FILES
                    10 {
                        # ....
                        stdWrap.ifEmpty.cObject = IMAGE
                        stdWrap.ifEmpty.cObject{
                            file = fileadmin/.../my_image.png
                        }
                        # ....
                    }
                }
            }
        }
    }
}

您可以使用所需的每个cObject。 查看Content Objects (cObject)

答案 1 :(得分:0)

试试这个:

 tt_content.menu {
  20 {
    108 = HMENU
    108 {
      special = directory
      special.value.field = pages
      1 = TMENU
      1.wrap = <div class="special_menu">|</div>
      1.NO {
        doNotLinkIt = 1
        stdWrap.cObject = COA
        stdWrap.cObject {
          # default image
          value = fileadmin/my/path/to/image.jpg
          10 = FILES
          10 {
            references {
                table = pages
                fieldName = media
            }
            renderObj = IMAGE
            renderObj {
                file {
                    width = 263c
                    height = 155c
                    maxW = 263c
                    maxH = 155c
                    import.data = file:current:publicUrl
                }

            altText.field = title
            imageLinkWrap = 1
            imageLinkWrap {
                enable = 1
                typolink.parameter.field = uid
                }
            }
            stdWrap.wrap = <div class="menu10_bild">|</div>
          }

          20 = TEXT
          20.field = title
          20.typolink.parameter.field = uid
          20.wrap = <div class="menu10_text">|

          30 = TEXT
          30.field = abstract
          30.wrap = <p>|</p></div><div class="w-clearfix">&nbsp;</div>
        }
      }
    }    
  }
}