How do I read tags from a files-blueprint?

  • On a page I provide PDFs for download
  • During the upload, the files blueprint “pdf.yml” is assigned to each PDF
  • In the blueprint “pdf.yml” I enter two tags each: language (de, en, fr, it …) and category (datasheet, catalog, flyer …)

I need these tags to create filters for “isotope” https://isotope.metafizzy.co/
Unfortunately I can’t find a way to read the tags from “pdf.yml” and output them in my template with a foreach loop.

I have created a comparable solution with subpages. Here the tags are in the page blueprint. Maybe this code just needs minimal tweaking?

<?php
$tags = $page->children()->listed()->pluck('tags', ',', true);
?>
<ul>
<?php foreach($tags as $tag): ?>
<li><a class="text-center" data-filter=".<?= html($tag) ?>" href="#"><?= html($tag) ?></a></li>
<?php endforeach ?>
</ul>

Thank you.

The same approach also works for files: $files->pluck('language', ',', true), of course, you need to define what $files is first…

Note that this doesn’t read the field content from the blueprint, but actually from the page/file content, where the file content comes from the meta data files.

Blueprints just create the forms for the Panel.

There might be situations where you do actually want to read stuff from blueprint files, though, for example the possible options from select fields or field labels, but I don’t think this is what you want to do.

1 Like

Thank you for your quick reply. Great!
As I suspected, it was just a small change, but sometimes you don’t see that particular tree in the forest…

Original:

$tags = $page->children()->listed()->pluck('tags', ',', true);

Modification:

$tags = $page->files()->pluck('tags', ',', true);

That’s how it worked: