Verwendung: Download-Element für Contao 5 umbauen

Markus Schindler - CodeSache.de's Avatar

Markus Schindler - CodeSache.de

12 Mar, 2026 11:43 AM

Produkt: Custom Elements Contao
Contao-Version: 5.7

Hallo zusammen,
ich habe ein altes Contao 4 RSCE Template das ich gerne auf Contao 5 umbauen möchte.
Hier das alte Teil:

<div class="downloadbox <?php echo $this->size ?> <?php echo $this->class ?>"<?php echo $this->cssID ?>>
<div class="innen">

 <div class="stern"></div>

 <?php if ($this->download): ?>

 <?php $objFile = \FilesModel::findByUuid($this->download);
 $file = \Input::get('file', true);
 $objFileSize = $this->getReadableSize(filesize($objFile->path));
 if ($file != '' && $file == $objFile->path)
 {
 \Controller::sendFileToBrowser($file);
 }
 ?>

 <div class="ueberschrift"><?= $this->ueberschrift ?></div>
 <div class="text"><?= $this->text ?></div>
 <div class="size">(<?php echo $objFileSize ?>)</div>

 <a href="{{env::request}}?file={{file::<?= $this->download ?>}}" title="<?= $this->ueberschrift ?>">Download</a>

 <?php endif ?>

</div>
</div>

So weit habe ich es anpassen können, aber die Datei wird nicht an den Browser übergeben und der Pfad /files/ hat einen / davor.

<div class="downloadbox <?php echo $this->size ?> <?php echo $this->class ?>"<?php echo $this->cssID ?>>
<div class="innen">

 <div class="stern"></div>
 <?php if ($this->download): ?>

 <div class="ueberschrift"><?= $this->ueberschrift ?></div>
 <div class="text"><?= $this->text ?></div>
 <div class="size"></div>

 <?php 
 $objFile = \Contao\FilesModel::findByUuid($this->download);
 $file = \Contao\Input::get('file', true);
 $objFileSize = $this->getReadableSize(filesize($objFile->path));
 if ($file != '' && $file == $objFile->path)
 {
 \Contao\Controller::sendFileToBrowser($file);
 }
 
 echo  $objFileSize;
 
 ?>

  <a href="{{env::request}}?file={{file::<?= $this->download ?>}}" title="<?= $this->ueberschrift ?>">Download</a>


<?php //$this->dumpTemplateVars() ?>


<?php endif; ?>
</div>
</div>

Vielleicht kann mir jemand das Template anpassen.

Vielen Dank schon mal

Markus

  1. 1 Posted by Markus Schindle... on 12 Mar, 2026 11:44 AM

    Markus Schindler - CodeSache.de's Avatar

    Hier das Element

  2. Support Staff 2 Posted by RockSolid Theme... on 13 Mar, 2026 10:46 AM

    RockSolid Themes's Avatar

    Vielen Dank für Ihre Nachricht.

    Ihre Frage betrifft Contao im Allgemeinen und hängt nicht direkt mit Ihrem RockSolid Theme zusammen. In unseren Support-Richtlinien weisen wir darauf hin, dass wir leider keinen allgemeinen Support für Contao anbieten können. Dennoch versuchen wir Ihnen, in diesem Fall, im Rahmen unserer Möglichkeiten weiterzuhelfen:

    Uns ist nicht bekannt wie ein Link auf {{env::request}}?file={{file::<?= $this->download ?>}} in Contao 4.13 funktioniert haben könnte.

    Sie können versuchen direkt auf {{file::<?= $this->download ?>}} zu verlinkten und dem Link das download-Attribut hinzufügen. Dafür ist allerdings erforderlich, dass die Datei sich in einem veröffentlichten Ordner befindet.

    Beispiel:

    <a href="{{file::<?= $this->download ?>}}" download title="<?= $this->ueberschrift ?>">Download</a>
    
  3. 3 Posted by Markus Schindle... on 13 Mar, 2026 12:05 PM

    Markus Schindler - CodeSache.de's Avatar

    Vielen Dank das Beispiel hat wunderbar funktioniert.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac