Unable to get the image from a structure field - Running Kirby 2.2

I’m running the kirby 2.2 beta. I’m having some issues getting the an image from the structured field. I’ve tried getting it in different ways but none seem to be working. Maybe I’m just a noob at this :joy: …or maybe it’s just a bug. Everything else works fine with the exception of the image/thumb. Anyways, here’s the test code I’m currently using and the blueprint:

<?php foreach(page('slides')->slides()->toStructure() as $slide): ?>
	<div class="slide" style="background-image: url();">

		<!-- Just test code.-->
		<div style="background: red; color: white; height: 200px; width: 100%; margin-top: 200px">

				<!-- This is the part that doesn't seem to be working -->		
				<?php echo thumb($slide->image($slide->background()), array('width' => 1440, 'height' => 650, 'crop' => true, 'upscale' => true, 'quality' => 80))->url() ?>


		<div class="slide-content wrap">
			<div class="slide-meta">
				<?php if ($slide->display_title()->isTrue()): ?>
				<h2 class="title"><?php echo $slide->title() ?></h2>
				<?php endif ?>

				<?php if ($slide->text()->isNotEmpty()): ?>
				<p class="summary"><?php echo $slide->text() ?></p>
				<?php endif ?>

				<?php if ($slide->button_text()->isNotEmpty() && $slide->button_link()->isNotEmpty()): ?>
				<a class="btn btn-big<?php ecco($slide->button_style() == 'btn-line', ' btn-line'); ecco($slide->button_style() == 'btn-dark', ' btn-dark')?>" role="button" href="<?php echo $slide->button_link() ?>">
					<?php echo html($slide->button_text()) ?>
				<?php endif ?>
	<?php endforeach ?>

title: Slides

pages: false
deletable: false
  type: image
  sortable: true

    label: Title
    type:  text
    label: Slides
    type: structure
    entry: >
      <h1>{{title}}</h1><br />
        label: Title
        type: text
        label: Display Title
        type: toggle
        text: yes/no
        label: Futured Slide Image
        type: select
        options: images
        required: true
        label: Description
        type: textarea
        label: Button Text
        type: text
        width: 1/2
        label: Button Style
        type: select
        width: 1/2
        default: btn-green
          btn-green: Solid Green
          btn-dark: Solid Black
          btn-line: Line
        label: Button Link
        type: text


I had been using the code above for kirby 2.1(with the exception of ->toStructure() of course) but I have updated the slides to the structured field type, that’s when it stopped working. Previously I was using a separate page for the slides and everything was working fine.

In the thumb line, you need to reference $page instead of $slide:

<?php echo thumb($page->image($slide->background()), array('width' => 1440, 'height' => 650, 'crop' => true, 'upscale' => true, 'quality' => 80))->url() ?>

Just tried it, didn’t work. It throws this error:

Fatal error: Uncaught The given image is invalid thrown in /Applications/MAMP/htdocs/kirby-copy/kirby/toolkit/lib/thumb.php on line 64

Ok, the page is not the current page, so it should rather be

<?php echo thumb(page('slides')->image($slide->background()), array('width' => 1440, 'height' => 650, 'crop' => true, 'upscale' => true, 'quality' => 80))->url() ?>

That seems to do the trick! Thank you! :+1:

Also thumbs can be handled a little more clearly in 2.2: https://twitter.com/getkirby/status/665129237117038593