Good Morning everyone,
i want to display pdf-files, that are loaded into a folder on the website.
That is my current code, but i don’t get a link displayed.
`<section id="program">
<h1><?= $data->title() ?></h1>
<ul>
<?php
foreach($page->documents()->filterBy('extension', 'pdf') as $pdf): ?>
<li>
<a href="<?= $pdf->url() ?>">
<?= $pdf->filename() ?>
(<?= $pdf->niceSize() ?>)
</a>
</li>
<?php endforeach ?>
`
This is my first project with kirby3 & PHP. So bear with me, if i’m missing some essential ideas.
Thank you in advance
cadars
2
Your code works perfectly to retrieve pdfs for the current page.
Or do you want to display pdfs from somewhere else?
1 Like
Is that a sort of one-pager setup? What is $data in your context?
Hi texnixe,
Yes, i have a onepager setup fetched from the kirby cookbook recipe:
The $data attribute is from the recipe:
foreach($pages->listed() as $section) {
snippet($section->uid(), ['data' => $section]);
}
(sorry for replying so late, private issues came sweeping by)
As far as i understand, because i collect the data differently i need to change the $page attribute?
Ok, the $data refers to the current one-pager section page and you have to use $data instead of $page to fetch the documents from this page:
<section id="program">
<h1><?= $data->title() ?></h1>
<ul>
<?php foreach($data->documents()->filterBy('extension', 'pdf') as $pdf): ?>
<li>
<a href="<?= $pdf->url() ?>">
<?= $pdf->filename() ?>(<?= $pdf->niceSize() ?>)
</a>
</li>
<?php endforeach ?>
</ul>
1 Like
So simple and i didn’t see it. Thank you very much.