{% for page in pages %}
{% if page.id starts with current_page.id|split('/')|slice(0,-1)|join('/') ~ '/sidebars/' %} {# page-specfic sidebars should be placed before global ones #}
{% endif %}
{% endfor %}
{% for page in pages %}
{% if page.id starts with 'sidebars/' %} {# global sidebars #}
{% endif %}
{% endfor %}