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:
controller:
// 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);
Blueprint:
marques:
label: Marques
type: structure
fields:
marquetitle:
label: Nom
type: text
marquedesc:
label: Description
type: textarea
buttons:
- italic
- bold
marqueillu:
label: Logo
type: files
multiple: false
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:
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;
}
}
}