Multiline toStructure()

It seems that toStructure() can’t handle multiline data, so what’s the best solution to overcome this issue?

At the moment I have something like this:

<?php foreach($page->overview()->toStructure() as $overview): ?>
    <section class="post">
        <h3><?php echo $overview->heading() ?></h3>
        <?php echo $overview->text()->kirbytext() ?>
    </section>
<?php endforeach ?>

And the page looks like this

Overview:

- heading: first header
  text: some text, which should be multiline data.

- heading: 2nd header
  text: but in some of these I NEED tables...!

Do you have a better idea? What did I miss here?

You can do it like this:

text: >
    single paragraph
text: |
   multiple paragraphs

   bla blablab akdjajf daj jdjf jfjd fjdj jfdj

Thank you very much, texnixe.
This works great. But I still need tables in some of them. Having the code directly in the .txt doesn’t work like anyplace else.
What is the smartest way for this?

That’s strange. Are you using kirbytext() to output the content?

Yes. It looks very funny, because then everything gets collapsed into the first <section>.

Have you made sure that your indentation is correct?

-
  title: >
    bla bla bla
  text: |
    |  1 | 2  |  3 | 4  | 5  |
    |---|---|---|---|---|
    |  1 |  2 | 4  | 6  |  7 |
    |  1 |  3 |  4 | 5  |  6 |
    |  1 |  3 |  5 |  7 |  8 |
    
    bla bla bla bla blub

:worried: I took a html table…
well well, this topic is solved.

HTML tables should work as well …

BTW.: If you want to use markdown table syntax, the markdown.extra option needs to be enabled in your config.php.

Your table is working, the HTML table wasn’t.
Bug or some other stuff going on?

I put an HTML table in and it worked, so not sure this is a bug. I’ve put this into a file:

-
  title: >
   bla bla bla
  text: |
    <table>
      <thead>
        <tr>
          <th>1</th>
          <th>2</th>
          <th>3</th>
          <th>4</th>
          <th>5</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>1</td>
          <td>2</td>
          <td>4</td>
          <td>6</td>
          <td>7</td>
          </tr>
        <tr>
          <td>1</td>
          <td>3</td>
          <td>4</td>
          <td>5</td>
          <td>6</td>
        </tr>
        <tr>
          <td>1</td>
          <td>3</td>
          <td>5</td>
          <td>7</td>
          <td>8</td>
        </tr>
      </tbody>
    </table>
    
    some more text here ...

Ok, it works. It is just VERY picky with the correct intendation.

Yep, the YAML syntax is very strict about relative indentation. :slight_smile:
If you use the structure field, you don’t have to care about that stuff though as Kirby will indent it properly for you.

As future reference:

A Markdown table does not allow row or cell spanning as well as putting multi-line text in a cell. The first row is always the header followed by an extra line with dashes “-” and optional colons “:” for forcing column alignment.