Title of field displaying before content

I have added an input field which allows the user to add multiple text items in this case for the purpose of categories. The outputted data is correct however it is displaying the title along with each one not sitting inside an individual span tag.

Here is the current output:
<span>- title: catagory1 - title: catagory2 - title: catagory3</span>

Desired outcome:
<span>catagory1</span> <span>catagory2</span> <span>catagory3</span>

Catagories:
  type: structure
  width: 1/3
  fields:
    title:
      type: text
<?php foreach ($page->siblings() as $project): ?>
    <span>
        <?= $project->Catagories() ?>
    </span>
<?php endforeach?>

Hi there,
you need to go through the structure as well, right now you’re just listing the child pages.

<?php foreach ($page->siblings() as $project): ?>
   <?php if($project->Catagories()->isNotEmpty()): ?>
      <?php foreach ($project->Catagories() as $category): ?>
            <span>
                <?= $category->title()->html() ?>
            </span>
        <?php endforeach?>
    <?php endif ?>
<?php endforeach?>

cheers
tom

I get this error with this code: Call to a member function title() on string

Not quite correct, you have to convert to a structure:

<?php foreach ($page->siblings() as $project): ?>
   <?php if($project->catagories()->isNotEmpty()): ?>
      <?php foreach ($project->catagories()->toStructure() as $category): ?>
            <span>
                <?= $category->title()->html() ?>
            </span>
        <?php endforeach?>
    <?php endif ?>
<?php endforeach?>

With this code I get this error: Kirby \ Exception \ InvalidArgumentException (error.invalidArgument)

Invalid structure data for “catagories” field on parent “Kreativzentrum”

Yeah you’re right… missed that one :upside_down_face:

Can you show us the content of that field in that page?

sure, here is the full code:

<?php foreach ($page->siblings()->listed()->children()->listed() as $project): ?>
    <div class="project-home-outer background-image drop-shaddow-dark related-10 fadeIn <?= $project->Shape() ?> <?= $project->Catagories() ?> background-image" style="background-image:url(<?=($site = $project->featureImage()->toFile()) ? $site->url() : ''; ?>)">
        <a class="button-link" href="<?= $project->url() ?>">
            <div class="background-image project-card-mobimg display-none-desktop" style="background-image:url(<?=($site = $project->featureImage()->toFile()) ? $site->url() : ''; ?>)">
            </div>
            <h4 class="white-text fade-in">
                <?= $project->title() ?>
            </h4>
            <p class="white-text p-small fade-in">
                <?= $project->Exerpt() ?>
            </p>
            <?php if($project->Catagories()->isNotEmpty()): ?>
                <p class="white-text p-small fade-in catagories-in-card">
                <?php foreach ($project->Catagories()->toStructure() as $category): ?>
                    <span>
                        <?= $category->title()->html() ?>
                    </span>
                <?php endforeach?>
                </p>
            <?php endif ?>
        </a>
    </div>
<?php endforeach?>

I didn’t want to see the code, but the actual content in the page that throws the error.

Additionally, please provide the stack trace for the error (left column of Whoops page under the error).

Okay yes here you go, here is the url for testing: https://realm-mango.com/

Thanks, that’s part of the information needed. I’ll try again:

What is stored in the incriminated field (in the catagories field in the content text file in the page “Kreativzentrum”)?

There is nothing in this field. I added the if statement checking if the field is not empty and this did not fix the issue either. (I have edited the code in the previous comment to demonstrate this.)

Additionally, when I added content to the field for Kreativzentrum, it is the next sibling which throws the error.

Which Kirby version are you using?

If you try to convert an empty field to structure, it should not throw an error but return an empty structure collection. So this is weird.

how do I check the version?

If you are using the Panel, you can see it in your System view. If not, in /kirby/composer.json

But is the field really empty in those cases where it throws an error? Because I have a feeling the field contains data, but data that Kirby cannot convert to a structure object. Hence the error.

good point, I had changed this field so old data was stored here. Thank you for helping me fix this.