How do i add a button to a blueprint

Hi, in this thread you suggested a blueprint with a structured field which worked very nicely, I need to extend this blueprint by adding a link after the itemtext field to open a pdf file - not sure how to do this - or i could add the link button at the end of the itemtext; what do you suggest?
Thanks for any help

Both options are possible. You can either just add the link in the textarea field (itemtext) with a Kirbytag (link: mypdf.pdf text: Download my super PDF), or you could just add a new field, for example a select field that would allow you to select one of the uploaded PDF files.

Thanks Sonja,
It’s easier for me (with my limited knowledge) to add the link to the itemtext field.
What would a select field with a link to a pdf look like?

If you look at the docs for the select field, you can restrict what the select field displays.

For example:

    label: PDF Files
    type: select 
    options: documents

That would tell the select field to only list files that have been uploaded to that page that are documents (md, pdf, doc, docx, xls, xlsx, ppt, csv, rtf). You can work with them in your template code like this. So you would do that within your loop that generates the information contained within the structure field. Ill create a little example of a link to one but I can see Sonja typing so she might beat me to it…

In your blueprint add the select within the structure field (extending the example from the other post):

title: Example

pages: false #no subpages allowed

    label: title
    type: text
    label: Items
    type: structure
        label: Item title
        type: text
        label: Item text
        type: textarea
        label: Link to PDF
        type: select
        options: documents

Then in your template:

$items = $page->items()->toStructure();
foreach($items as $item): ?>
  <h2><?= $item->itemtitle()->html() ?></h2>
  <?= $item->itemtext()->kirbytext() ?>
  <?php if($file = $item->filelink()->toFile()): ?>
    <a href="<?= $file->url() ?>">Download PDF</a>
  <?php endif ?>
<?php endforeach ?>

If you want to limit the options to PDF files only (in case you upload other files of type document), you would have to use a plugin that allows you to limit the options further.

Shouldn’t files be set to true?

Thanks for this, Could you explain pages: false, files: true.
If I have a collection of pdf files is it best to put them in a pdf folder inside the assets folder?

If you want to link to them in your content files, don’t put them in the assets folder.

files: false

Means you can’t upload files to the page. True is the default, so you don’t have to put that in. Please see the docs for details.

File settings:

Subpage settings:

Apart from setting these to true or false, you can also define what templates/blueprints are allowed for subpages, how they should be sorted etc.

For files, you can also define fields, for example, if you want to add captions, or in your example with the PDF files, you could use these meta data to store the title of your PDF file, so you could use that in your link (if you use the select field)

You can disable the ability to create subpages or the ability to add files to a page by setting these to true or false accordingly at the top of the blue print. These are true by default, so in the absence of being told otherwise, you will be able to upload files and create subpages, without adding these lines to the blueprint.

It’s best to upload them to the page they belong to. The assets folder is more for things like CSS images.