Problem outputting the field value instead of converting to a file object


I have a problem, there is the images link’s and I don’t found the problem in my php code. The print screen is attached. The name of my image don’t have a spacebar.

Thank you, Delphine

Looks like you are just outputting the field value instead of converting to a file object. Please post your template code.

this is code ?

No, that’s not the code for the output above. In your first screenshot, you have a link right after an opening main element…

Maybe from the note.php template, if you are working with the Starterkit?

Ah ok, I get it. Maybe this code ?


<article class="casalina-excerpt">
  <a href="<?= $casalina->url() ?>">
      <figure class="img" style="--w: 16; --h:9">
        <?php if ($cover = $casalina->cover()): ?>
        <?= $cover->crop(10, 50) ?>
        <?php endif ?>

      <h2 class="note-excerpt-title"><?= $casalina->title() ?></h2>
      <time class="note-excerpt-date" datetime="<?= $note->published('c') ?>"><?= $casalina->published() ?></time>
    <?php if (($excerpt ?? true) !== false): ?>
    <div class="note-excerpt-text">
      <?= $casalina->text()->toBlocks()->excerpt(280) ?>
    <?php endif ?>

No, that doesn’t look like it either.

Looks like you are working with the Starterkit but have made some changes?

Don’t you know where you have made the changes?

Yes, I change the files in the folder “models”.

class casalinaPage extends Page
    public function cover()
        return $this->content()->cover()->toFile() ?? $this->image();

    public function published($format = null)
        return parent::date()->toDate($format ?? 'd M, Y');

Do you know where is the problem? Thank you si much for your help

Well, the problem is that you are just outputting the field value of the field that contains that teqt.png file, while you would have to output write code like this:

<?php if ($image = $page->nameOfField()->toFile()): ?>
  <a href="<?= $file->url() ?><?= $file->name() ?></a>
<?php endif ?>

Unless you have a model in place with the cover method that already does this internally. But for this to work, the CasalinaPage model (think it must be uppercase) must apply to the page where you are using this code, then calling toFile() wouldn’t be necessary.