symfonysylius

What "resource: |" does mean in routes.yaml?


I'm trying to figure out with Sylius routing, based on Symfony framework. I found that code

sylius_admin_channel:
    resource: |
        alias: sylius.channel
        section: admin
        templates: "@SyliusAdmin\\Crud"
        except: ['show']
        redirect: update
        grid: sylius_admin_channel
        permission: true
        vars:
            all:
                subheader: sylius.ui.configure_channels_available_in_your_store
                templates:
                    form: "@SyliusAdmin/Channel/_form.html.twig"
            index:
                icon: share alternate
    type: sylius.resource

But I could not find any information what is it | for resource. Any help?

Thanks.


Solution

  • It's the YAML syntax for a multi-line string (that preserves newlines).

    So sylius_admin_channel is a mapping that has two keys (resource and type) whose values are both string types.

    It can be confusing to see in this instance because the string happens to also be valid YAML. I edited your question to include syntax highlighting for YAML which makes this a little more obvious, visually.

    If I didn't know any better, I would have guessed that the | is there in error and resource should actually have a mapping type for its value. If you remove the |, then same symbols that were within that string still produce valid YAML for the whole file, but the value of resource would be a mapping, rather than a string.

    Notice the difference in syntax highlighting, compared to the yaml in the question with the | removed:

    sylius_admin_channel:
        resource: 
            alias: sylius.channel
            section: admin
            templates: "@SyliusAdmin\\Crud"
            except: ['show']
            redirect: update
            grid: sylius_admin_channel
            permission: true
            vars:
                all:
                    subheader: sylius.ui.configure_channels_available_in_your_store
                    templates:
                        form: "@SyliusAdmin/Channel/_form.html.twig"
                index:
                    icon: share alternate
        type: sylius.resource