Access user files

the problem is probably to read the structure field, a dump gives the following output:

Kirby\Cms\Field Object
(
    [dates] => Kirby\Cms\Field Object
        (
            [dates] => - 
  title: Mis nit Dis!
  date: 2021-01-15 18:00
  location: 'Bücherschiff '
  city: Basel
  website: ""
  festival: ""
- 
  title: Mis nit Dis!
  date: 2021-09-05 15:30
  location: Kannenfeldpark
  city: Basel
  website: ""
  festival: ""
- 
  title: Zoff und Zank
  date: 2021-05-02 11:00
  location: Kufki
  city: Uster
  website: ""
  festival: ""
- 
  title: Zoff und Zank
  date: 2021-06-06 16:00
  location: BAU3 Chinds-Chöpf
  city: Basel
  website: https://bau3.ch
  festival: ""
        )

)

what is the syntax to loop the structurfield to get the values?
this has not worked since 3.4

foreach ($page->dates()->toStructure() as $dates):

what has changed in the new kirby version that it no longer works?

Maybe create an issue on GitHub with a stripped down use case based on a Starterkit so we can reproduce this? There have been changes to the Structure field, yes.

I found how to get the content of the structurfield:

<?php 
$sd = $page->dates()->toArray();
foreach ($sd['dates']->toStructure() as $dates): 
?>

That looks weird, but maybe the issue is how you add that field to your MembersPage model. Unfortunately, your model above does not contain that field.

Unfortunately, since the update, the images (from the user profile) can no longer be read out.

error message:

Invalid YAML data; please pass a string

this time it has nothing to do with the structure field, the data comes from a files field.

blueprint

  cover:
    label: 
      de: Datei auswählen
      fr: Select files
      it: Select files
    type: files
    layout: cards
    max: 3
    width: 1/3
    translate: false
    size: small

template

	<section class="grid-col-40 gallery">

				<?php
				$image_gallery = $page->cover()->yaml();

				foreach($image_gallery as $image):
				$imgs = $kirby->user($page->userid())->image($image);
				if ($image):	
				echo $imgs->thumb(
					[
						'autoOrient' => true,
						'crop'       => false,
						'blur'       => false,
						'grayscale'  => false,
						'width'     => 500,
						'quality'    => 90
					]
				);
				endif;
				endforeach;
				

				?>

			</section>

output without yaml()

$image_gallery = $page->cover();
echo $image_gallery;

- > mobydickrecycled_probefotos_sabineburger_081.jpg - ei_5361_web.jpg - dscf7539.jpg

why the - > at the beginning of the list ?

That’s probably how the content is stored in the content file.

But you are posting issue after issue and I still don’t know if the previous one was solved or not. Also, if you report error messages, it would be helpful to see the code that throws the error and the stacktrace. We don’t get anywhere with only bits and pieces out of context, I’m afraid.

the current problem was actually solved before the update. did you change something in the latest kirby version at yaml()?

template

  	<section class="grid-col-40">
  		<a id="back-button" href="<?php echo $page->parent()->url() ?>"><img src="/content/back.svg"></a>
  		<h1><?php echo $page->title() ?></h1>
  		<?php echo $page->about()->kirbytext() ?>

  		<ul class="adress">
  			<li><?php echo $page->street() ?></li>
  			<li><?php echo $page->zip() ?> <?php echo $page->city() ?></li>
  			<?php if($page->website()!= ""): ?>
  				<li><a href="<?php echo $page->website() ?>">Webseite</a></li>
  			<?php endif ?>
  		</ul>


  		<ul class="shows">
  			<?php  
  			$sd = $page->dates()->toArray();
  			foreach ($sd['dates']->toStructure() as $dates): ?>
  				<ul class="show">
  				<?php if($dates->website()!= ""): ?>
  					<a href="<?php echo $dates->website(); ?>">
  				<?php endif ?>
  				<li class="event-date"> <?php echo date("d.m.Y, H:i", strtotime($dates->date())); ?></li>
  				<li class="event-title"> <?php echo $dates->title(); ?></li>
  				<li> <?php echo $dates->location().", ".$dates->city(); ?></li>
  				<?php if($dates->website()!= ""): ?>
  					</a>
  				<?php endif ?>
  				</ul>
  			<?php endforeach; ?>	

  		</ul>
  	</section>

  	<section class="grid-col-40 gallery">

  		<?php
  		$image_gallery = $page->cover()->yaml();




  		dump($image_gallery);

  		
  		foreach($image_gallery as $image):
  		$imgs = $kirby->user($page->userid())->image($image);
  		if ($image):	
  		echo $imgs->thumb(
  			[
  				'autoOrient' => true,
  				'crop'       => false,
  				'blur'       => false,
  				'grayscale'  => false,
  				'width'     => 500,
  				'quality'    => 90
  			]
  		);
  		endif;
  		endforeach;
  		

  		?>

  	</section>

model

<?php

class MembersPage extends Page
{
  public function children()
  {
    $usersPages = [];
    $users      = kirby()->users();
    foreach ($users as $key => $user) {
      $userPages[] = [
        'slug'     => Str::slug($user->username()),
        'num'      => $user->indexOf($users),
        'template' => 'member',
        'model'    => 'member',
        'content'  => [
          'title'    => $user->username(),
          'type'    => $user->member_type()->value(),
          'street'    => $user->street(),
          'city'    => $user->city(),
          'zip'    => $user->zip(),
          'website'    => $user->website(),
          'about'    => $user->about(),
          'userid'    => $user->id(),
          'cover'    => $user->cover(),
          'canton'    => $user->canton(),
          'dates'  => $user->dates(),
          'blackboard'  => $user->blackboard()
        ]
      ];
    }
    return Pages::factory($userPages, $this);

  }
}

as far as i understand yaml () makes strings that start with - an array. only that probably no longer works in my case.

I think the whole problem is that you pass fields instead of strings and arrays to your field keys in your model.

1 Like

okay, that helped.

model
'cover' => $user->cover()->yaml(),

template
$image_gallery = $page->cover()->yaml();

Is my guess correct that yaml() from a string that starts with a - makes an array?