Fetch image from parent structure with pluck


I would need to filter content by marques. Marques have a name and a logo, they are created in the parent page with a structure. I can easily show them all, and filter them all with their Name, but I’m unable to show their correspondant Logo:


// add the categories filter
    if($marque = param('marque')) {      
      //Used for multiple words categories
      $marque = urldecode(param('marque'));    
      $items = $items->filterBy('marq', $marque, ',');
$allmarques = $items->pluck('marq', ',', true);


  label: Marques
  type: structure        
      label: Nom
      type: text
      label: Description
      type: textarea
        - italic
        - bold
      label: Logo
      type: files
      multiple: false


 <?php foreach($allmarques as $marque): ?>
<?= html($marque) ?>
<?php endforeach ?>

this works correctly

child blueprint:

  label: Marque
  type: multiselect
  options: query
    fetch: page.parent.parent.marques.toStructure
    text: "{{ structureItem.marquetitle }}"
    value: "{{ structureItem.marquetitle }}"

I tried with value: value: "{{ structureItem.marqueillu }}" value: "{{ structureItem.marqueillu.url }}"
I thought I could fetch image this way, but I have an error in the panel .

At this moment I can make it work using directly the structure in the template:

<?php foreach ($page->marques()->toStructure() as $detailsmarque): ?>
<?php if($logomarque = $detailsmarque->marqueillu()->toFile()):?>
   <img src="<?= $logomarque->crop(70)->url() ?>" width="70" height="70"
   alt="logo <?= html($detailsmarque->marquetitle()) ?>">
<?php endif?>

But I can filter anymore the content correctly in relatons with others categories :frowning:

Thank you for any help.

What would work, but only if all structure items have an image (otherwise you get an error in the Panel):

  label: Marque
  type: multiselect
  options: query
    fetch: page.parent.marques.toStructure
    text: "{{ structureItem.marquetitle }}"
    value: "{{ structureItem.marqueillu.toFile.id }}"

Therefore, I think you would better stick with storing the title, and then in your template, find the structure item with that title and get the image from the item.

Thank you Sonja, yes this would be the prefered solution (if I change value I will need to rewrite all products value ?? in text files)

this where I’m lost:

 <?php $test = $page->marques()->toStructure()?>
<?php if($test->marquetitle() == param('marque')):?>
<?= html($marque) ?> ok - how to fetch marqueillu here
<?php endif;?>

I do have any idea about how to proceed to fetch the image here

If you have already stored the image as value or whatever, then yes.

Me, too. What is the parameter doing here? I thought this was about getting the image(s) from the marq field?

What I think you should be doing in the page with the marq field:

// fetch the structure items from the parent page
$items = $page->parent()->marques()->toStructure();
// loop through the values stored in the `marq` field
foreach ($page->marq()->split(',') as $marq) {
  // try to find  a structure item by title
  if ($item = $items->findby('marquetitle', $marq) {
    // convert the file id stored for that item to file
    if ($logo = $item->marqueillu()->toFile()) {
      echo $logo;

Sorry Sonja, English + PHP is a hard combo for me…
Your exemple helped me a lot :wink:
I made it work this way:

<?php $logos = $page->marques()->toStructure();?>                      
 <?php if ($item = $logos->findby('marquetitle', $marque)) :?>
 <?php if ($logo = $item->marqueillu()->toFile()) :?>
   <?= $logo;?>
 <?php endif;?>
 <?php endif;?>

Yep, I understand. As would French be for me (although I do understand some French–in writing, not when people talk).