Structured fields image url

Hi all -

I’m retreiving an image from a structured field but not sure how to retrieve the url for it correctly so that it’s relative to both the content level (subpage of 'courses;) and works running on my local via the 8888 port on my local. I’ve been using the site url config value until now but not sure how to do it via the yaml method (open to other ways of course too). Any help appreciated

    <?php $poi = $page->poi()->yaml();
    foreach($poi as $poi): ?>
      <div class="row poi">
        <div class="col-lg-4">
          <img src="<?php echo $poi['poi_image'] ?>">
        </div>
        <div class="col-lg-8">
          <h4><?php echo $poi['poi_name'] ?></h4>
          <p><?php echo $poi['poi_description'] ?></p>
        </div>
      </div>
    <?php endforeach ?>

See this cookbook recipe in the section about accessing images from a structure field.

Thank you! :slight_smile:

I don’t think it’s considered good style to use the same variable for the array you loop through, and the variable used inside the array, btw.

Hmm thanks. As you see I’m still learning. What would be the better alternative?

The standard is to use some sort of plural or something denominating an array/collection to loop through and a singular for the variable used inside the loop. Some examples:

foreach($items as $item) ...
foreach($collection as $item) ...
foreach($points as $point)...
foreach($articles as $article)...
foreach($array as $arrayItem) ...
foreach($pois as $poi)...