打字稿-仅在使用URL链接文件的情况下链接它 [英] Typoscript - Link a file only if it exists using URL
问题描述
我正在使用TemplavoilàPlus,我有一个由用户填写的字段,标题为field_title
.
我使用此字段通过Typoscript对象路径为FCE的其他字段创建URL/HTML.
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.
常量:
file = fileadmin/datasheets/|.pdf
设置:
lib.field_datasheet = TEXT
lib.field_datasheet {
field = field_title
wrap = <a href="{$file}"></a>
}
问题在于,仅当文件/URL存在时,我才想这样做. 首先,我想检查一下我创建的URL是否未链接到404页面. 然后,我认为检查文件大小是否为0会更容易. 经过两天的工作,到处查看之后,我意识到这些解决方案都不是一件容易的事……
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…
我认为我使用stdWrap.rawUrlEncode
,file:current:size
,if.isTrue.data
,FILE
等有很多答案,但是显然,Typoscript不是为初学者而设计的,而且我似乎找不到如何正确地排列所有内容,以及如何正确使用所有这些内容.
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
但是真正困难的部分是从我使用Typoscript创建的URL中获取文件大小. 我很漂亮,肯定有一种方法只能用Typoscript来做到这一点,因为我知道一个人可以从其uid中获取文件的大小…
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…
或者也许我应该坚持检查该网址是否未指向404页面. 也许有一个我没想到的简单解决方案!
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 ! =)
我正在使用Typo3 7.6
推荐答案
您可以为此使用文件链接.未经测试,应该是这样的:
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
}
}
不确定如果文件不存在该怎么办.它可能什么也不显示,在这种情况下,您可以使用ifEmpty.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.
有关文件链接的更多信息: https://docs.typo3.org/typo3cms/TyposcriptReference/Functions/Filelink.html
More on filelink: https://docs.typo3.org/typo3cms/TyposcriptReference/Functions/Filelink.html
这篇关于打字稿-仅在使用URL链接文件的情况下链接它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!