2017-05-10 41 views
0

作爲TYPO3液體的新手,我想知道是否有一種簡單的方法來創建一個PDF文件的鏈接位於文件列表中你會在簡單的HTML如下:TYPO3液體:如何創建鏈接到PDF文件(無需下載,無顯示)

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

我無法找到一個解決方案,到目前爲止,不會要求延期或不會照片直接顯示PDF頁面上(<flux:field.inline.fal name="settings.image" required="1" maxItems="1" minItems="1"/>)

如若/這可以用<f:link.external href="filePathOnServer/file.pdf">完成嗎? (我有此刻的另一個問題阻止我檢查,如果這個工程...)

編輯

我使用<f:link.external>沒有工作嘗試。目前我正在使用(非流體)<a>-tag ...

+0

你爲什麼要流體視圖助手如果鏈接是靜態的?使用'Click here to open pdf (in a new window)'作爲絕對路徑,可能使用''作爲文本部分「點擊此處打開pdf(在新窗口中)」。 –

+0

@ HeinzSchilling我只是想知道是否有一種方法......我認爲可能有更簡單的方法使用流體標籤......正如我已經說過的,我是新來的typo3-fluid ;-) – Kathara

回答

1

我不得不做同樣的事情,我通過編寫一個自定義ViewHelper來獲得網站URL來解決它。

視圖助手:

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

流體模板:

{namespace ext = Vendor\MyExt\ViewHelpers} 

<f:link.external target="_blank" 
    uri="{ext:internal(path: 'uploads/tx_myext/myfile.pdf')}"> 
    Link 
</f:link.external> 
+0

感謝您的好解決方案。我相信我想用我簡單的標籤去做,但這可能會派上用場。 :) – Kathara