Can't get a selected PDF file in the panel to show up on the page

Hey there,

so I got that accordion module and it’s working fine with the module plugin. Now I’m trying to customize it so I can use it for a career site.

Here’s what I got so far for the blueprint of said module:

title: Accordion Career module
options:
  preview: false
  template: false
  url: true
  delete: true

fields:
  title:
    label: Modul-Titel
    type: text

  accordiontype:
    label: Accordion Typ
    type: radio 
    default: checkbox
    options:
      checkbox: checkbox
      radio: radio
  accordions:
    label: Stellen
    type: structure
    modalsize: large
    entry: >
      {{header}}<br />
      {{content_aufg}}<br />
      {{content_anf}}<br />
      {{content_vor}}<br />
      {{content_biet}}<br />
      {{content_pdf}}<br />
  
    fields:
      header:
        label: Name der Stelle
        type: text
      content_aufg:
        label: Inhalt (Ihre Hauptaufgaben)
        type: textarea
      content_anf:
        label: Inhalt (Unsere Anforderungen)
        type: textarea
      content_vor:
        label: Inhalt (Ihre Voraussetzungen)
        type: textarea
      content_biet:
        label: Inhalt (Wir bieten Ihnen)
        type: textarea
      content_pdf:
        label: PDF
        type: select
       options: files 

The different content textareas are for what the company needs, what the applicant can expect and so on. For the PDF part I want a selectable list of die PDF files of the career page - which works so far.

The problem I have is, even after searching through the forums for the past couple of hours, that I can’t get a PDF download link in my template. I tried a couple of things I found here (this or this for example) and tried to make it fit my needs, but since I’m not really a coder, more a designer, I can’t get it to work.

Here’s the template part for the accordions I got:

<section class="section-text">			
             
           <?php $accordions = $module->accordions()->yaml() ?>
        <?php $first = a::first($accordions) ?>
                
        
            <?php foreach($accordions as $accordion): ?>
			<label class="accordion">
				<input type='<?php echo html($module->accordiontype()) ?>' name='<?php echo html($module->accordiontype()) ?>-accordion' <?php if($accordion == $first) echo ' checked="checked"' ?>>
				<div class="accordion__header"><?php echo $accordion['header'] ?></div>
				<div class="accordion__content">
					<h6>Ihre Hauptaufgaben:</h6>
					<p><?php echo kirbytext($accordion['content_aufg']) ?></p>
					<h6>Unsere Anforderungen:</h6>
					<p><?php echo kirbytext($accordion['content_anf']) ?></p>
					<h6>Ihre Voraussetzungen:</h6>
					<p><?php echo kirbytext($accordion['content_vor']) ?></p>
					<h6>Wir bieten Ihnen:</h6>
					<p><?php echo kirbytext($accordion['content_biet']) ?></p>
				</div>
			</label>
            <?php endforeach ?>
</section> 

So far I came to the concusion that I can’t get it to work with the yaml() and structure fields and select field. It doesn’t work the same way and I’m guessing I just don’t understand how it would work including a “file exists” query.

I appreciate every help I can get on this.

Thanks in advance
Daniel

Using yaml, $accordion['content_pdf'] will output the filename of the selected PDF as a string.

The toFile() function you’ve seen in the topics you mentioned can only work when chained with a field object (i.e. if you deal with your structure with the toStructure() method).

You’ll have to retrieve the file from the string. Assuming your $module variable acts as a $page one :

<?php $filename = $accordion['content_pdf'];
      if ($pdf = $module->files()->get($filename)): ?>

<h6>Download PDF :</h6>
<a href="<?php echo $pdf->url() ?>"><?php echo $filename ?></a>

<?php endif; ?>

Would be the way to go.

1 Like

Hey sylvainjule,

that does the trick! Works perfectly, thank you very much :smile:

Still learning all those different functions kirby provides…

Daniel