Structure field, file types and url parsing

Hi, I’m trying to builit a simple structured articles and so far I have in the blueprint:

  press:
    label: Press
    fields:
      press:
        label: On en parle
        type: structure
        columns:
          press_title: true
          press-published: true
          files: true
        fields:
          press_title:
            label: Titre
            type: text
            width: 1/4
          press-published:
            label: date de publication
            type: date
            width: 1/4
          files:
            label: files
            type: files
            width: 1/2
  • I trying to query only file type ‘documents’ and ‘audio’. I’ve tried
query: page.documents

But how do I add ‘audio’ as well in the query range?

and in the template:

<bside class="press">
  <h2 class="h1">On en parle</h2>
  <div>
    <section class="column text">
    <ul>
        <?php foreach ($page->press()->toStructure() as $press): ?>
        <li><?= html::a($press->url(), $press->press_title()) ?></li>
        <?php endforeach ?>
      </ul>
      </section>
  </div>
</bside>
  • it works in my layout but I can’t parse the files URL. The result is the homepage??? instead of the files path of the files included in the structured field.

Many thanks for any help.

N

A structure item doesn’t have a URL, what are you trying to do here?

I guess you want to do that in your structure field’s files field?

query: page.documents.add(page.audio)

could work.

I’m trying to get the file path of the selected documents inside the structure item. Is it possible? I’ve thought that if I can add a file inside a structure field, it should be possible to extract the file path URL? ;/

Yes, it works, great.

Is it documented in the online guide? I’ve searched but with no luck.

Many Thx.

N

Ok, the files selected in the files field can now be converted to a file object with toFile()(if it is a single file):

<?php foreach ($page->press()->toStructure() as $press): ?>
  <?php if ($file = $press->files()->toFile()): ?>
    <?= $file->url() ?>
  <?php endif ?>
<?php endforeach ?>

If your files field contains multiple files, you would call toFiles(), but then you need a loop to loop through the files collection per structure item.

Hey almost perfect.
I’ve had to add the html::a( + $press->press_title() like this in order to have proper urls:

    <ul>
        <?php foreach ($page->press()->toStructure() as $press): ?>
  <?php if ($file = $press->files()->toFile()): ?>
    <li><?= html::a($file->url(), $press->press_title()) ?></li>
  <?php endif ?>
<?php endforeach ?>
      </ul>

Thanks again for this perfect support!

N