How to nest structure field?

Hi! all ,
I’m looking for a little hand to achieve something like this :

I tried with a page builder, or the structure field, but either way i’m stuck at the same place which is how you nest the bookshops inside their respective city/country

Thanks in advance for any help, hint.

Happy holidays to all :fireworks:.

Here the codes used :

Usint a structure field and creating the cities as subpages :

  • Page

    • subpage
      • structure field
    • subpage
      • structure field
    <?php foreach($page->children() as $city): ?>
      <div class="row"> 
    
        <h1><?php  echo ($city->title()) ?></h1>
    
        <?php
          $bookshops = $page->children();
          $stores = new Structure();
          $key = 0;
      
          foreach($bookshops as $p) {
            foreach($p->stores()->toStructure() as $item) {
              $stores->append($key, $item);
              $key++;
            }
          }
    
          foreach ($stores as $store): ?>                 
            <?php if ($store->picture()->isNotEmpty() && $image = $page->image( $store->picture() )): ?>
            <img src="<?php echo thumb($image, array('width' => 80,'quality' => 80, 'crop' => true ))->url(); ?>">  
            <?php endif ?>
            <?php echo $store->bookshopName()->kt() ?>
            <?php echo $store->bookshopAdresse() ?>
            <?php echo $store->bookshopurl() ?>
          <?php endforeach ?>
    
      </div>
    <?php endforeach  ?>
    

Using the pagebuilder field :

template

  <?php foreach($page->builder()->toStructure() as $section): ?>
    <?php snippet('builder/' . $section->_fieldset(), array('data' => $section)) ?>
    <?php snippet('builder/bookshops/' . $section->_fieldset(), array('data' => $section)) ?>
  <?php endforeach ?>

builder/cityname

  <div class='city'>
    <?php echo $data->cities()->kt() ?>
  </div>

builder/bookshops/bookshops

<div class="shop-wrap">
  <?php if ($data->picture()->isNotEmpty() && $image = $page->image( $data->picture() )): ?>
    <img src="<?= $image->url() ?>">
  <?php endif ?>
  <div>
    <a href="<?= $data->bookshopurl() ?>"><?= $data->bookshopName() ?></a>
    <p ><?= $data->bookshopAdresse() ?></p>
  </div>
</div>

If the cities are your subpages and the shops are a structure field in each city subpage, your code should be something like this:

<?php foreach($page->children() as $city): ?>
    <div class="row"> 

      <h1><?php  echo ($city->title()) ?></h1>

      <?php
        $bookshops = $city->stores()->toStructure();
 
        foreach($bookshops as $store):
         if ($store->picture()->isNotEmpty() && $image = $page->image( $store->picture() )): ?>
          <img src="<?php echo thumb($image, array('width' => 80,'quality' => 80, 'crop' => true ))->url(); ?>">  
          <?php endif ?>
          <?php echo $store->bookshopName()->kt() ?>
          <?php echo $store->bookshopAdresse() ?>
          <?php echo $store->bookshopurl() ?>
        <?php endforeach ?>

    </div>
  <?php endforeach  ?>
1 Like

Thx a lot @texnixe , it did work :confused:.
Sorry to have bothered for such a simple thing :pensive: . I wish you a great week-end.