Possible problem parsing kirbytext within YAML structured field

Hello,

I think I’ve found a bug, but wanted to outline the issue before filing on GitHub…

I’m trying to provide a list of related external links on certain pages. To do this, I’ve added a structured list, like so:

related:
- [Kirby website](http://getkirby.com)
- (twitter: getkirby text: Follow Kirby on Twitter)

I have the following template:

<section>
    <h1>Related Links</h1>
    <ul>
        <? foreach($page->related()->yaml() as $related): ?>
        <li><?= kirbytext($related) ?></li>
        <? endforeach ?>
    </ul>
</section>

…which generates the following HTML:

<section>
    <h1>Related Links</h1>
    <ul>
        <li><p><a href="http://getkirby.com">Kirby website</a></p></li>
        <li><br>
<b>Notice</b>:  Trying to get property of non-object in <b>/Users/paulrobertlloyd/Sites/bradshawsguide/kirby/core/kirbytext.php</b> on line <b>39</b><br>
        </li>
    </ul>
</section>

Note that, while standard markdown is parsed correctly, any kirbytext tags throw the following error:

Notice: Trying to get property of non-object in /Users/paulrobertlloyd/Sites/bradshawsguide/kirby/core/kirbytext.php on line 39

It seems kirbytext gets in a tangle when placed inside an array (inspecting the output using a::show, it looks like kirbytext outputs an array itself, which might be why I’m seeing this issue).

Of course, I could just avoid using kirbytext tags inside this related field… except I’ve created a custom tag which I’d really like to use here.

Should I file a bug?

Best,

Paul

The field content you posted is no valid YAML:

If a line contains a colon and a space directly following it, the part before the colon is interpreted as the key and the rest as the content. You need to wrap the second line in quotes to force string parsing:

- [Kirby website](http://getkirby.com)
- "(twitter: getkirby text: Follow Kirby on Twitter)"

You can also omit the spaces, but that’s far harder to remember and debug.

And alternative would be to just split your list:

<section>
    <h1>Related Links</h1>
    <ul>
        <? foreach($page->related()->split('-') as $related): ?>
        <li><?= kirbytext($related) ?></li>
        <? endforeach ?>
    </ul>
</section>
1 Like

Ah ha, that’s ingenious (possibly obvious…?). Thanks, works like a charm!

Ah, of course. That fixes it. Think I’ll go with @texnixe’s solution, but certainly worth keeping this in mind. Thanks!

I have opened an issue on GitHub about the strange error that does not relate to the actual issue so that problems like this are easier to find in the future.