Pregunta

In a fluid template, I would like to output a linked file's size.

I'm using f:link.page to link to the file, as I think this is the way to do it (please correct if not).

<f:link.page class="download" pageUid="fileadmin/redaktion/download/papers/{paper.download}" {paper.author}">PDF</f:link.page>

As I'm already using the extension ml_links on the site, I thought I could pass the link through lib.parseFunc_RTE, but

<f:format.html parseFuncTSPath="lib.parseFunc_RTE"><f:link.page class="download" pageUid="fileadmin/redaktion/download/papers/{paper.download}" {paper.author}">PDF</f:link.page></f:format.html>

just wraps it into p.bodytext.

Do I have to use a different syntax to apply f:format.html TO f:link.page - or is there a better way to do it (via a fluid or vhs viewhelper)?

¿Fue útil?

Solución 4

When i use fluidcontent i have vhs extension installed aswell and then just use:

<f:format.bytes decimals="1">{v:media.size(path: '{file}')}</f:format.bytes>

This outputs clean readable sizes like "28.2 MB".

Otros consejos

Actually custom VH is fastest way to achieve that, i.e. basing on this VH, you'll need to replace size param with a file path, and then use i.e. filesize function of PHP to fetch the size in bytes.

Here's my VH:

https://gist.github.com/ursbraem/9645542

I've simplified the original a little, outputting "KiB" for file size is too technical for me.

The easiest way is to use native TYPO3 FAL parameter originalFile.size :

{audio.0.originalFile.size -> f:format.bytes()}

If you are using VHS you may consider https://fluidtypo3.org/viewhelpers/vhs/master/Media/SizeViewHelper.html (in combination with f:format.bytes).

In newer TYPO3 versions you can use the originalResource.size attribute of a FileReference object.

{file.originalResource.size -> f:format.bytes()}

or in your case:

{paper.download.originalResource.size -> f:format.bytes()}

TYPO3 10

I needed a file size output for a DCE module in TYPO3 10, this is what I came up with, using VHS:

<f:format.bytes><v:media.size><v:format.trim characters="/"><f:uri.typolink parameter="{item.link}" /></v:format.trim></v:media.size></f:format.bytes>

Explained:

  • f:uri.typolink generates the full path I need for v:media.size
  • v:media.size requires the path without a leading slash, v:format.trim removes this character.
  • f:format.bytes displays the output from v:media.size in KB or MB.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top