Typoscript - Link a file only if it exists using URL

百般思念 提交于 2019-12-01 11:50:30
Rudy Gnodde

You can probably use filelink for that. Without testing it, it should be something like:

lib.field_datasheet = TEXT
lib.field_datasheet {
  field = field_title
  wrap = |.pdf
  filelink {
    path = fileadmin/datasheets/
    file.field = field_title
  }
}

Not sure what that does if the file isn't there though. It probably shows nothing, in which case you can use ifEmpty.field = field_title to just show the text.

More on filelink: https://docs.typo3.org/typo3cms/TyposcriptReference/Functions/Filelink.html

Why don't you let TYPO3 decide whether the file exist and it's worth to build a link?

Your problem could be that you have nothing to become linked. (empty A-tag)

I would try something like:

Constants:

filePath = fileadmin/datasheets/|.pdf

Setup:

lib.field_datasheet = TEXT
lib.field_datasheet {
   // use the 'filename' as text to be linked
   field = field_title
   // now build the link:
   typolink.parameter {
       field = field_title
       wrap = {$filePath}|
   }
}

Thanks to Rudy's answer, I've been able to solve my problem. So that it can be useful to others, here is the bit of Typoscript I've used :

lib.field_datasheet = TEXT
lib.field_datasheet {
  value {
    field = field_title
    wrap = |.pdf
    }

  filelink {
    path = /fileadmin/datasheet/
    target = _blank
    altText = PDF icon
    titleText = Download datasheet

    //Personalize the icon, the file must be named pdf.png            
    icon_link = 1
    icon = 1
    icon {
      path = fileadmin/icons/
      ext = png
      }
    }
 }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!