I got a bilingual page (german and english) and some PDF downloads that are listed with this snippet
<?php foreach($page->files() as $f) : ?>
<a title="<?php l::get('download_file') ?>" href="<?php echo $site->url().'/get/'.$f->filename() ?>" target="_blank">
<h2 id="<?php echo $f->name() ?>"><?php e($f->title()->empty(), $f->filename(), $f->title()->kirbytextRaw()); ?></h2>
<?php e(!$f->title()->empty(), $f->filename().'<br>') ?>
<span class="filesize"><?php echo $f->niceSize(); ?></span><br>
<?php echo $f->description()->kt(); ?>
<?php endforeach ?>
I.e. all files in the page folder are listed and the description is fetched from the
file.pdf.de.txt. Now I want to who only some files depending on the current language or different versions like
file.en.pdf. Is there a built in way to do this?
If theres no build in way I guess I could create a custom filter but I don’t know how … so any help on that will be appreciated too!
Thanks! Actually I already found this thread but wanted to wait if there’s a built in way which is not the case as I conclude from your answer …
Is it possible to make this filter “global” so I can say
filterBy('language') and it automatically detects the current language? It would be perfect if the filter works like this:
FILE DE EN
example3.pdf X X
COLL. OF … FILES 3 4
I’m too tired, I think you don’t even need a custom filter, you can simply do sth like this (no tested though)
$files = $page->files()->filterBy('filename', '*=', $site->language()->code());
The custom filter is only necessary if you want to achieve the opposite, i.e. filter by files that do not contain a specific string.
Thanks, but this won’t cover the case where a single file (
example3.pdf) should be available to all languages …
True, I missed that, but all you need is add an
How can I add an
or condition? And how should I code the condition “has no language suffix”?
(In the mean time I decided another way to go fur my current project, but it would be interesting to know how this works, though …)