YAML Structured content broken after upgrade to Kirby 2

So I ended up doing a fresh install and brought over by hand just my site-specific files in my site’s existing Kirby 1 installation and things are up and running again on Kirby 2.

There are a couple issues with the upgrade. One with the (former) search plugin, which I’ll have to refactor to make use of the new plugin system. This I expected.

The other has to do with YAML structured field display. This was working perfectly on Kirby 1, but I can’t see any documentation that YAML structured field rendering had changed.

Here’s my template code, YAML structure, and the resulting array:

It seems like the problem is that the ‘Number’ and ‘URL’ field labels are not being parsed correctly. Am I overlooking something simple here?

I think it has to do with the way the content is entered into the content file. This is what the entries of a structure field look like in Kirby 2:

Questions: 
-
  q: What is Kirby?
  a: Kirby is the greatest CMS in the world.
-
  q: Do I need a license?
  a: Yes, we have to make a living.

As regards the search: you don’t need a plugin, the functionality has been built into Kirby 2. You may want to check out the Algolia plugin, though.

Could you please post the content and your code as code blocks? Screenshots make it really hard for us to debug.

Sure, sorry.

Here’s the relevant section of template code:

		    <ul class="navlist">
		    	<?php $volumes= yaml($page->volumes()) ?>
		    	<?php a::show($volumes) ?>
		    	<?php foreach($volumes as $volume): ?>
		    	<li>		    			
		    		<a href="<?php echo $volume['URL'] ?>" class="link article_title">Volume <?php echo $volume['Number'] ?></a>
		    	</li>		    			
				<?php endforeach ?>		    					    	
		    </ul>

Here’s the YAML structure:

Title: Volumes
----
Volumes:

Volume40Issue1-2:
	Number:		40, Issue 1-2
	URL:		volumes/40issue1-2

Volume39Issue3-4:
	Number:		39, Issue 3-4
	URL:		volumes/39issue3-4

Volume39Issue1-2:
	Number:		39, Issue 1-2
	URL:		volumes/39issue1-2

Volume38Issue3-4:
	Number:		38, Issue 3-4
	URL:		volumes/38issue3-4

Volume38Issue1-2:
	Number:		38, Issue 1-2
	URL:		volumes/38issue1-2

Volume37Issue3-4:
	Number:		37, Issue 3-4
	URL:		volumes/37issue3-4

Volume37Issue1-2:
	Number:		37, Issue 1-2
	URL:		volumes/37issue1-2

Volume36:
	Number:		36, Issue 1-4
	URL:		volumes/36issue1-4

Volume35:
	Number:		35, Issue 1-4
	URL:		volumes/35issue1-4

Volume34Issue3-4:
	Number:		34, Issue 3-4
	URL:		volumes/34issue3-4

Volume34Issue1-2:
	Number:		34, Issue 1-2
	URL:		volumes/34issue1-2

Volume33Issue3-4:
	Number:		33, Issue 3-4
	URL:		volumes/33issue3-4

Volume33Issue1-2:
	Number:		33, Issue 1-2
	URL:		volumes/33issue1-2

Volume32Issue3-4:
	Number:		32, Issue 3-4
	URL:		volumes/32issue3-4

Volume32Issue1-2:
	Number:		32, Issue 1-2
	URL:		volumes/32issue1-2

Here’s the resulting array:

Array
(
    [Volume40Issue1-2] => Array
        (
            [0] => Number:		40, Issue 1-2
            [1] => URL:		volumes/40issue1-2
        )

    [Volume39Issue3-4] => Array
        (
            [0] => Number:		39, Issue 3-4
            [1] => URL:		volumes/39issue3-4
        )

    [Volume39Issue1-2] => Array
        (
            [0] => Number:		39, Issue 1-2
            [1] => URL:		volumes/39issue1-2
        )

    [Volume38Issue3-4] => Array
        (
            [0] => Number:		38, Issue 3-4
            [1] => URL:		volumes/38issue3-4
        )

    [Volume38Issue1-2] => Array
        (
            [0] => Number:		38, Issue 1-2
            [1] => URL:		volumes/38issue1-2
        )

    [Volume37Issue3-4] => Array
        (
            [0] => Number:		37, Issue 3-4
            [1] => URL:		volumes/37issue3-4
        )

    [Volume37Issue1-2] => Array
        (
            [0] => Number:		37, Issue 1-2
            [1] => URL:		volumes/37issue1-2
        )

    [Volume36] => Array
        (
            [0] => Number:		36, Issue 1-4
            [1] => URL:		volumes/36issue1-4
        )

    [Volume35] => Array
        (
            [0] => Number:		35, Issue 1-4
            [1] => URL:		volumes/35issue1-4
        )

    [Volume34Issue3-4] => Array
        (
            [0] => Number:		34, Issue 3-4
            [1] => URL:		volumes/34issue3-4
        )

    [Volume34Issue1-2] => Array
        (
            [0] => Number:		34, Issue 1-2
            [1] => URL:		volumes/34issue1-2
        )

    [Volume33Issue3-4] => Array
        (
            [0] => Number:		33, Issue 3-4
            [1] => URL:		volumes/33issue3-4
        )

    [Volume33Issue1-2] => Array
        (
            [0] => Number:		33, Issue 1-2
            [1] => URL:		volumes/33issue1-2
        )

    [Volume32Issue3-4] => Array
        (
            [0] => Number:		32, Issue 3-4
            [1] => URL:		volumes/32issue3-4
        )

    [Volume32Issue1-2] => Array
        (
            [0] => Number:		32, Issue 1-2
            [1] => URL:		volumes/32issue1-2
        )

)

So this structure is no longer recommended? https://getkirby.com/blog/structured-field-content

That post is 4 years old :slight_smile:

Could you please do the following with your code above:

  • Select your code
  • Click on the </>button in the text editor

This is how you wrap code.

Alternatively, you can wrap it with ‘backticks’

```php
your code here

> I can't post the YAML structure as code here it seems like (it's getting interpreted by the forum editor.

Yes you can by wrapping it like I mentionned above. The best language for highlight is ini instead of php for yaml code
1 Like

Yep, of course. I suppose that’s why I’m asking when and how the structured content handling has changed since then.

Sorry, my answer didn’t bring much contribution…
All posts that are more than a couple years old on the blog need to be taken with a pinch of salt. Kirby has changed quite a lot in that time. I usually prefer the forum and the docs to the blog :wink:

Could you give it a shot this way:

Title: Volumes
----
Volumes:

Volume40Issue1-2:
	Number:	40, Issue 1-2
	URL:	volumes/40issue1-2

Volume39Issue3-4:
	Number:	39, Issue 3-4
	URL:	volumes/39issue3-4

Volume39Issue1-2:
	Number:	39, Issue 1-2
	URL:	volumes/39issue1-2

Volume38Issue3-4:
	Number:	38, Issue 3-4
	URL:	volumes/38issue3-4

Volume38Issue1-2:
	Number:	38, Issue 1-2
	URL:	volumes/38issue1-2

Volume37Issue3-4:
	Number:	37, Issue 3-4
	URL:	volumes/37issue3-4

Volume37Issue1-2:
	Number:	37, Issue 1-2
	URL:	volumes/37issue1-2

Volume36:
	Number:	36, Issue 1-4
	URL:	volumes/36issue1-4

Volume35:
	Number:	35, Issue 1-4
	URL:	volumes/35issue1-4

Volume34Issue3-4:
	Number:	34, Issue 3-4
	URL:	volumes/34issue3-4

Volume34Issue1-2:
	Number:	34, Issue 1-2
	URL:	volumes/34issue1-2

Volume33Issue3-4:
	Number:	33, Issue 3-4
	URL:	volumes/33issue3-4

Volume33Issue1-2:
	Number:	33, Issue 1-2
	URL:	volumes/33issue1-2

Volume32Issue3-4:
	Number:	32, Issue 3-4
	URL:	volumes/32issue3-4

Volume32Issue1-2:
	Number:	32, Issue 1-2
	URL:	volumes/32issue1-2

Note: It may not copy well to the panel… I removed the extra tab between the key and value. Try it directly in your content file.

Thanks, didn’t make a difference unfortunately.

Hmm. I can only recommend that you keep trying to format your yaml differently. Although Kirby has changed a lot, it should be able to parse valid yaml content !

I’ve copied your code in http://www.yamllint.com/ and it returned errors. Didn’t even want to parse the darn thing :frowning:

In the meantime, if you want a nice structure field which you’ll be able to edit directly from the panel, try this blueprint:

title: Volumes
fields:
  title:
    label: Title
    type:  text
  volumes:
    label: Volumes
    type: structure
    style: table
    fields:
      name:
        label: Volume Name
        type: text
      number:
        label: Number
        type: text
      url:
        label: URL
        type: page

You can then easily access it in your template either via either $page->volumes()->yaml() or $page->volumes()->toStructure() methods.

So, still not sure what’s up with the YAML parsing, but I managed to obviate my need for it at the moment. Thought there should be a better way of creating multiple layers of menu pages, and I found one. This site is an academic journal that has a list of volumes linking to a single volume page. On the single volume pages there is a list of articles. Some of these article title listings are linked to article pages.

To automate the list of volumes, I’m just using this now, where table-of-contents is the template for the single volume list page:

foreach($page->children()->index()->flip()->filterBy('template','table-of-contents') as $volume):

Maybe I’m missing something but it does seem strange that there isn’t a way to limit $page->children to a single level without filtering. Is there a way to do that?

Thanks for all the help, I really appreciate it!

You just added something after children :wink:
foreach($page->children()->flip() as $volume):

index()-> is meant to build a recursive array of children and grandchildren :wink:

1 Like

Regarding the YAML parse issue: Does it work if you indent with spaces instead of tabs? Tabs are invalid in YAML.