1

Being new to TYPO3 fluid I was wondering if there's an easy way to create a link to a PDF-file which is located in the filelist as you would in simple html as follows:

<a href="filePathOnServer/file.pdf">Click here to open pdf (in a new window)</a>

I couldn't find a solution so far that wouldn't require an extension or that wouldn't render the pdf direclty on the page (<flux:field.inline.fal name="settings.image" required="1" maxItems="1" minItems="1"/>)

Should/Can this be done with <f:link.external href="filePathOnServer/file.pdf"> ? (I've got another problem at the moment preventing me from checking if this works...)

EDIT

I've tried using <f:link.external> which didn't work. For the time being I'm using the (non-fluid) <a>-tag...

Community
  • 1
  • 1
Kathara
  • 1,226
  • 1
  • 12
  • 36
  • Why do you want a fluid ViewHelper if the link is static? Use `Click here to open pdf (in a new window)` as absolute path maybe with `` for the text part "Click here to open pdf (in a new window)". – Heinz Schilling May 10 '17 at 18:21
  • @HeinzSchilling I was just wondering if there was a way... I thought there might be an easier way using the fluid-tags... As I've said already, I'm new to typo3-fluid ;-) – Kathara May 11 '17 at 06:54
  • 1
    Does this answer your question? [Link to file in Fluid – how to specify storage?](https://stackoverflow.com/questions/40388543/link-to-file-in-fluid-how-to-specify-storage) – cweiske Jul 26 '22 at 13:11
  • It's been a long time since I asked this question but @cweiske yes, it does. It is exactly what I was looking for back then. :) – Kathara Aug 23 '22 at 12:53

1 Answers1

1

I had to do the same thing and I resolved it by writing a custom ViewHelper just to get the site url.

ViewHelper:

class InternalViewHelper extends AbstractViewHelper
{
    /**
     * Renders a link to a specific path from the root path of TYPO3.
     *
     * @param string $path The path to an internal resource relative to the TYPO3 site URL.
     * @return string The absolute URL to the given resource.
     */
    public function render($path)
    {
        $siteUrl = GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
        return htmlspecialchars($siteUrl . $path);
    }
}

Fluid Template:

{namespace ext = Vendor\MyExt\ViewHelpers}

<f:link.external target="_blank"
   uri="{ext:internal(path: 'uploads/tx_myext/myfile.pdf')}">
     Link
</f:link.external>
hoorider
  • 111
  • 4
  • Thanks for your nice solution. I believe for what I want I'm going with the simple a-tag but this might come in handy some time. :) – Kathara May 11 '17 at 06:58