1

Is it possible to have a repeating route in the bolt cms? I made a route in my routing.yml that looks like this

language:
    path: /{locale}/{slug}
    defaults: { _controller: controller.frontend:template, template: 'page.twig' }

It renders the page.twig using the template function on the Frontend controller. So when I dump the variables in my page.twig in this way

{{ dump(app.request.get('locale')) }}
{{ dump(app.request.get('slug')) }}

This will output.

"en"
"stackoverflow"

But I want a repeating route that would work like this.

language:
    path: /{locale}/{slug**}
    defaults: { _controller: controller.frontend:template, template: 'page.twig' }

So when I access an url like:

bolt.dev/en/slug1/slug2

I will receive a array in my view named slug and it will output

[slug1, slug2]
DB93
  • 610
  • 2
  • 5
  • 16

1 Answers1

2

Bolt uses Symfony routing under the hood, and there isn't a concept of array parameters.

What you can do is capture the entire url after your locale and then split it in Twig, so:

language:
    path: /{locale}/{slug}
    defaults: 
        _controller: controller.frontend:template
        template: 'page.twig'
    requirements:
        slug: .+

This allows the slash to be captured as part of slug, so assuming your url is /en/slug1/slug2 then doing app.request.get('slug') will return slug1/slug2 which you can then split in Twig:

{% for slug in app.request.get('slug')|split('/') %}
    {{ slug }}
{% endfor %}
Ross Riley
  • 826
  • 5
  • 8