I honestly don’t know which is faster.
However the two examples (mine and yours) apply to a little bit different use-cases:
In your example, you convert every file to a single file object to use it within the loop. This is fine, if the order the Selector field stores the filenames doesn’t matter or fits your needs.
In my example, I create a file collection object out of all selected files which you can filter/sort/search further (just like you can do with $page->files() ). In most cases, this might not be needed, but I though I provide a “one fits all” solution.
Your way of using the Selector field value is completely fine, though!
please try to use the following code snippet where you want to use the intro image and let me know if it works!
<?php
// Convert the selected filename to a full file object
$filename = $page->intro();
$intro = $page->files()->find($filename);
?>
<!-- Use the file object -->
<img src="<?php echo $intro->url(); ?>" />
Yeah, I don’t know why @Andi doesn’t use the $page variable in his code (probably some one-page layout stuff), but of course, the snippet I posted should be adapted accordingly.
<section class="intro" id="intro">
<h1 class="headline--big"><?php echo $data->headline()->html() ?></h1>
<h2 class="subheadline"><?php echo $data->subheadline()->html() ?></h2>
<?php
// Convert the selected filename to a full file object
$filename = $data->intro();
$intro = $data->files()->find($filename);
?>
<!-- Use the file object -->
<img src="<?php echo $intro->url(); ?>" />
Hi,
this plugin is awesome and it helped me a lot. However I have a functionality request:
Is it possible to add the option page to query images from another page?
something like this:
query:
page : another page
label : selector label
type : selector
autoselect: first
types :
- image
I just double check with the latest Kirby (+ Panel) release 2.2.1 and the latest Selector release 1.5.1. Unfortunately, I’m unable to reproduce the issues your experiencing.
As far as I can see the latest release is fully compatible to both Kirby 2.2.1 and Kirby 2.1.2.
Have you made sure that you’re really using the latest stable releases of both Kirby and the Selector?
Just a side note. We now have a testkit for all default fields, third-party fields and other panel-related tests. The selector field is already included there and we couldn’t find any issues either: https://github.com/getkirby/testkit@DieserJonas feel free to use that for your own testing needs. One of our goals would be to introduce this as a central place for all plugin developers to build real-life test cases.
This looks really great! One question: if I wanted to remove the edit button, how would I go about doing that? I’m quite happy that this plugin works in a structured field, except for the edit button. I don’t mind losing that functionality there however (it is very nice mind you), and removing the button would make it a bit less cramped in the structured field entry form. In addition, removing edit and select button text would be nice.