Hi, I have a foreach template where each a tag will route to different links…some of the items will link to a pdf which is filed under the page and some of the items will link to an external link that I have named “Link” in my content document. What would be the “if” statement to say if there is a pdf, use that but if not, use the link? Here is the code I have for using the link…
Hi! Yes, here is the complete loop. What I envision is an “if” statement before the a href line that would give the option to link to the pdf file if it is available for that particular item. Any thoughts would be greatly appreciated!
<?php foreach ($page->children()->listed() as $place): ?>
No problem. So I have a portfolio of my work - some of the items I want to link to are external urls (links) and others are pdf files of designs. The pdfs are embedded within the individual portfolio folders. So basically, I’m trying to do an “if” statement that says if there is no pdf within the page folder, it should link to the file, which is in the page’s content folder.
Sorry if this is confusing! I’m new to Kirby and trying to finish a project for a class! Thank you for your help!
What I would do is use two different fields for the the file or a pdf:
Blueprint:
fields:
typeOfLink:
label: Choose link type
type: radio
options:
external: External link
pdf: PDF file
pdf:
type: files
max: 1
query: page.files.filterBy('extension', 'pdf')
when:
typeOfLink: pdf
link:
type: url
when:
typeOfLink: external
Template:
<?php if ($place->typeOfLink()->value() === 'external' && $place->link()->isNotEmpty()) : ?>
<!-- code for external link -->
<?php elseif ($place->typeOfLink()->value() === 'pdf' && $file = $place->pdf()->toFile()) : ?>
<a href="<?= $file->url() ?>"<This is the link to the file</a>
<?php endif; ?>