Select one case to show on homepage

I have the following question:
I want to show one case I have selected on my homepage. My blueprint is the following:

title: Case

columns:
  - width: 2/3
    fields:               
      uitgelichtcase:
        label: Toon Case
        type: select
        options: query
        query: site.children.template("actueel").children.template("cases").children
            
        
  - width: 1/3
    sections:
      meta:
        type: fields
        fields:
          uploads:
            label: Images
            type: files  

So now I have a dropdown where I can choose a case. Now I want to choose one case and display this. I have the following code.

<section class="case case--highlighted">
    <?php if($page->uitgelichtcase()): ?>
    <?php foreach($cases = $site->find('actueel/cases')->children()->listed()->sortBy('date', 'asc')->flip()->limit(1) as $case): ?>   

            <div class="case__top">
    <div class="container">
        <div class="case-block case-block--highlighted">
            <?php if($image = $case->cover()->toFile()): ?>  
            <picture class="case-block__bg" style="background-image:url(<?= $image->crop(1920, 1080)->url() ?>);"></picture>
            <?php endif ?> 
            <a class="overlay-link" href="<?= $case->url() ?>"></a>
        </div>
    </div>
</div>
 

            </section>



<?php endforeach ?>              
           <?php endif ?>

First I start with the check if the field is empty. If it is not empty the foreach loop starts. But I don’t understand how I now integrate the chosen “case” (from my dropdown).

Can anybody give me some advice where to start?

Thanks!

Since you want to select only one case, you don’t need a foreach loop, but only fetch the case:

<?php if($case = $page->uitgelichtcase()->toPage()) : ?>
<section class="case case--highlighted">

    <div class="case__top">
        <div class="container">
            <div class="case-block case-block--highlighted">
                <?php if ($image = $case->cover()->toFile()): ?>  
                <picture class="case-block__bg" style="background-image:url(<?= $image->crop(1920, 1080)->url() ?>);"></picture>
                <?php endif ?> 
                <a class="overlay-link" href="<?= $case->url() ?>"></a>
            </div>
        </div>
    </div>
 
</section>           
<?php endif ?>
1 Like

Oh wow that is much easier than what I was thinking.
Thank you!!!