Structure Method

Good Evening Kirby Family.

at this moment i’m gona try to use the structure method whit a simple team section:

HTML Markup:


      <div id="row">
        <div class="col-md-3 col-sm-6 team">
          <div class="thumbnail"> <img src="assets/img/team/01.jpg" alt="..." class="team-img">
            <div class="caption">
              <h3>John Doe</h3>
              <p>Director</p>
            </div>
          </div>
        </div>
        <div class="col-md-3 col-sm-6 team">
          <div class="thumbnail"> <img src="assets/img/team/02.jpg" alt="..." class="img-circle team-img">
            <div class="caption">
              <h3>Mike Doe</h3>
              <p>Senior Designer</p>
            </div>
          </div>
        </div>
        <div class="col-md-3 col-sm-6 team">
          <div class="thumbnail"> <img src="assets/img/team/03.jpg" alt="..." class="img-circle team-img">
            <div class="caption">
              <h3>Jane Doe</h3>
              <p>Senior Designer</p>
            </div>
          </div>
        </div>
        <div class="col-md-3 col-sm-6 team">
          <div class="thumbnail"> <img src="assets/img/team/04.jpg" alt="..." class="img-circle team-img">
            <div class="caption">
              <h3>Karen Doe</h3>
              <p>Project Manager</p>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

and also in the blueprint file:

tab4:
    label: Team Section 
    type:  tabs 
  teamtitle:
    label: Team Title 
    type:  text
  teamtext:
    label: Team Description
    type:  textarea
  team:
    label: Team Members
    type: structure
    entry: >
      {{image}}: {{name}} - ({{role}})  
    fields:
      label:
        image: Team Image
        type: image
      name:
        label: Team Name
        type: text
        icon: font
      role:
        label: Team Role
        type: text  

but when i create a entry in the panel i have this result


what did i do wrong, because i cant see the image. :confused:.

Thanks very much ! :blush:

Check out this post: Structure field & multiple images preview

thanks you, i fixed that already!.

i’m a bit confused whit the structure post in the docs

i have one example in my snippet:

 <div id="row">
        <div class="col-md-3 col-sm-6 team">
          <div class="thumbnail"> <img src="assets/img/team/01.jpg" alt="..." class="team-img">
            <div class="caption">
              <h3>John Doe</h3>
              <p><?= $page->team()->role()->toStructure() ?></p>
            </div>
          </div>
        </div>
       
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

and between the <p> tags i replace the role whit

<?= $page->team()->role()->toStructure() ?>

and my result is:


what exacly i do wrong?

Thanks!

Since your field is called team it should be:

<?php
$team = $page->team()->toStructure();
foreach($team as $teamMember): ?>
<?php echo $teamMember->role() ?>
<?php endforeach ?>

okay, can i do the same thing whit the image?, and what exactly does foreach here?.

The loop loops through the team collection, please read up on the structure field in this cookbook recipe

Edit: your blueprint is not correct, either:

label:
    image: Team Image
    type: image

Your field is called label, instead of image…

image:
    label: Team Image
    type: image

okay i will do it!.

the blueprint sems to be correct now;

image:
        label: Team Image
        type: image

and in the snippet:

<?php
                  $team = $page->team()->toStructure();
                  foreach($team as $teamMember): ?>
                  <?php echo $teamMember->image() ?>
                  <?php endforeach ?>

but the image is invisible

Yes, because you don’t get the image like that

<?php if($image = $teamMember->image()->toFile()) echo $image->html() ?>

okay so thats my full snippet now:

 <div id="row">
        <div class="col-md-3 col-sm-6 team">
          <div class="thumbnail"> <img src="<?php if($image = $teamMember->image()->toFile()) echo $image->html() ?>" alt="..." class="team-img">
            <div class="caption">
              <h3><?php
              $team = $page->team()->toStructure();
              foreach($team as $teamMember): ?>
              <?php echo $teamMember->name() ?>
              <?php endforeach ?></h3>
              <p><?php
              $team = $page->team()->toStructure();
              foreach($team as $teamMember): ?>
              <?php echo $teamMember->role() ?>
              <?php endforeach ?></p>
            </div>
          </div>
        </div>
       
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

and my result:

is that a problem whit the image code?, i have inspect the code again but i really cant find the problem, i have already create some member entrys in the panel.

Your image is not within the loop, so the variable $teamMember is not known at that time and should throw an error, if you had debug turned on. Later you create the same loop twice, which is unnecessary.

What about this?

<div class="row"> <!-- don't know why you are using an id here? -->
  <?php $team = $page->team()->toStructure(); ?>
  <?php foreach($team as $teamMember): ?>
    <div class="col-md-3 col-sm-6 team">
      <div class="thumbnail">
        <img src="<?php if($image = $teamMember->image()->toFile()) echo $image->html() ?>" alt="..." class="team-img">
        <div class="caption">
          <h3><?php echo $teamMember->name() ?></h3>
          <p><?php echo $teamMember->role() ?></p>
        </div>
      </div>
    </div>
  <?php endforeach; ?>
</div>

I don’t know your markup in detail, so it may be that …

<div class="col-md-3 col-sm-6 team">

… and its closing </div> needs to be moved out of the foreach loop!?

its the code of a template, i dont change anything whit id or classes.

now i have try it whit your example:

  <?php $team = $page->team()->toStructure(); ?>
  <?php foreach($team as $teamMember): ?>
    <div class="col-md-3 col-sm-6 team">
      <div class="thumbnail">
        <img src="<?php if($image = $teamMember->image()->toFile()) echo $image->html() ?>" alt="..." class="team-img">
        <div class="caption">
          <h3><?php echo $teamMember->name() ?></h3>
          <p><?php echo $teamMember->role() ?></p>
        </div>
      </div>
    </div>
  <?php endforeach; ?>
</div>

and these are my blueprint fields:

team:
    label: Team Members
    type: structure
    entry: >
      {{image}}: {{name}} - ({{role}})  
    fields:
      image:
        label: Team Image
        type: image
      name:
        label: Team Name
        type: text
      role:
        label: Team Role
        type: text  

but these sems to be correct

and my result is:

The above line does not make sense

Either:

<?php if($image = $teamMember->image()->toFile()) echo $image->html() ?>

($image->html()creates an image tag, so you can’t put that inside of the source attribute of an image tag)

or

<?php if($image = $teamMember->image()->toFile()): ?>
<img src="<?php  echo $image->url() ?>" alt="..." class="team-img">
<?php endif ?>

okay now i understand it a bit!.

and what is the problem whit the footer?, it was not there before.


is that a problem because i dont close a tag?

Well, unfortunately, my crystal ball does not reveal such things, so please check with developer tools.

1 Like

i cant see anything in the error console, but yes i will check it. Thanks a looot for the help @texnixe and @flokosiol :blush:

You need to check if you have an identical number of opening and closing divs, this won’t show up as an error in the error console.

i have check it all. these seems to be correct all:

  <?php $team = $page->team()->toStructure(); ?>
  <?php foreach($team as $teamMember): ?>
    <div class="col-md-3 col-sm-6 team">
      <div class="thumbnail">
        <?php if($image = $teamMember->image()->toFile()): ?>
        <img src="<?php  echo $image->url() ?>" alt="..." class="team-img">
        <?php endif ?>
        <div class="caption">
          <h3><?php echo $teamMember->name() ?></h3>
          <p><?php echo $teamMember->role() ?></p>
        </div>
      </div>
    </div>
  <?php endforeach; ?>
</div>
<div id="team" class="text-center">
  <div class="overlay">
    <div class="container">
      <div class="col-md-8 col-md-offset-2 section-title">
        <h2><?= $page->teamtitle()->html() ?></h2>
        <hr>
        <p><?= $page->teamtext()->html() ?></p>
    </div>
    </div>
    </div>
   </div>
      <?= snippet('team-members') ?>

Edit:
okay sorry, now it looks great. the snippet code was at the wrong row.

thanks a lot again!