1
votes

I am using Templavoilà Plus and I have one field which the user complete with a title called field_title. I use this field to create an URL/HTML for other fields of my FCE, using Typoscript Object Path.

Constants:

file = fileadmin/datasheets/|.pdf

Setup:

lib.field_datasheet = TEXT
lib.field_datasheet {
 field = field_title
 wrap = <a href="{$file}"></a>
}

The problem is that I want to do that only if the file/URL exists. First, I thought of checking if the URL I create didn't link to a 404 page. Then I thought it would be easier to check if the file size wasn't 0. After working on that for two days, and after looking everywhere, I realized neither of these solutions were easy…

I think I have bits of answers, using stdWrap.rawUrlEncode, file:current:size, if.isTrue.data, FILE, etc… but obviously, Typoscript isn't made for beginners, and I can't seem to find how to put everything in the right order, and how to use all this properly.

I think I could manage the condition using something like :

if.isTrue < .10 #.10 containing the size of the file
if.value = 0

But the part which really is difficult is getting the file size from a URL I created using Typoscript. I'm pretty there must be a way to do that only with Typoscript since I know one can get the size of a file from its uid…

Or maybe I should just stick to checking if that URL don't lead to a 404 page. Or maybe there is a simpler solution I didn't think about!

Any help would be greatly appreciated, sorry if that problem is too easy to solve, and thank you very much already for reading this post ! =)

EDIT : I'm using Typo3 7.6

3

3 Answers

2
votes

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

1
votes

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}|
   }
}
1
votes

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