Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

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. I edited your question to include syntax highlighting for YAML which makes this a little more obvious, visually.

If you remove the | then resource, then the same symbols within that string would still be valid YAML, but the value of resource would be a mapping, rather than a string.

With the | removed: (notice the difference in syntax highlighting, compared to the yaml in the question)

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading