# Data of Files output from a Structure Field

**URL:** <https://forum.getkirby.com/t/data-of-files-output-from-a-structure-field/11703>\
**Category:** Questions\
**Tags:** v2\
**Created:** [November 24, 2018, 4:52pm UTC](https://forum.getkirby.com/t/data-of-files-output-from-a-structure-field/11703 "2018-11-24T16:52:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dersven](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/dersven/32/133_2.png) [@dersven](https://forum.getkirby.com/u/dersven)\
**Post date:** [November 24, 2018, 4:52pm UTC](https://forum.getkirby.com/t/data-of-files-output-from-a-structure-field/11703/1 "2018-11-24T16:52:05Z")

</div>

i created in my blueprint a structure field to output zum PDF.Files

```
      downloads:
        label: Downloads
        type: structure
        style: table
             fields:
             label: PDF-Datei
             type: select 
             default: 
             options: files

```

but i get no infos about the filename, the size or the link to the file in my template.  
how can i access to it

```
<?php
// get all PDF-Files
$downloads = $page->downloads()->toStructure();
foreach($downloads as $download): ?>
 <li><a href="<?= $download->url() ?>"><?= $download->filename() ?> <span>(<?= $download->niceSize() ?>)</span></a></li>
<?php endforeach ?>

```

---

<div class="post-metadata">

**Author:** ![jimbobrjames](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jimbobrjames/32/5802_2.png) [@jimbobrjames](https://forum.getkirby.com/u/jimbobrjames)\
**Post date:** [November 24, 2018, 6:09pm UTC](https://forum.getkirby.com/t/data-of-files-output-from-a-structure-field/11703/2 "2018-11-24T18:09:05Z")

</div>

You need to put value of the select field through `file()`. At the moment you just have the filename stored in the structure field. You need to pick up the value, check the file exists, and work on it from there.

Something like this i think, but not tested…

```auto
<?php
// get all PDF-Files
$downloads = $page->downloads()->toStructure();
foreach($downloads as $download): 
$pdffile = $page->file($download->PDF-Datei());?>
<?php if($pdffile): ?>
<li><a href="<?= $pdffile->url() ?>"><?= $pdffile->filename() ?> <span>(<?= $pdffile->niceSize() ?>)</span></a></li>
<?php endif ?>   
<?php endforeach ?>

```

Looks like there is an error in the blueprint code you posted above - the select field does not have name key, so you will need to change the code i just gave you above accordingly.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [November 25, 2018, 12:02am UTC](https://forum.getkirby.com/t/data-of-files-output-from-a-structure-field/11703/3 "2018-11-25T00:02:25Z")

</div>

The code @jimbobrjames posted above is correct, but you can shorten it a bit:

```auto
<?php
// get all PDF-Files
$downloads = $page->downloads()->toStructure();
foreach($downloads as $download): 
  <?php if($pdfFile = $download->fieldname()->toFile()): ?>
    <li><a href="<?= $pdfFile->url() ?>"><?= $pdfFile->filename() ?> <span>(<?= $pdfFile->niceSize() ?>)</span></a></li>
  <?php endif ?>   
<?php endforeach ?>

```

With a blueprint like this:

```auto
  downloads:
        label: Downloads
        type: structure
        style: table
        fields:
          fieldname:
            label: PDF-Datei
            type: select 
            options: files

```

Apart from the missing fieldname, there’s also an empty default option, I’m surprised your blueprint worked like this.

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:25pm UTC](https://forum.getkirby.com/t/data-of-files-output-from-a-structure-field/11703/4 "2025-02-06T17:25:46Z")

</div>

Archived on February 6, 2025, 5:25pm UTC


