Add a default param for an archive page

I have an archive page that shows current year events. In the same page users can click and view the previous events by a taxonomy list (2017, 2016, etc).

Now in my twig template I have this:

    {% if uri.param('year') %}
      {% set year = uri.param('year') %}
      {% set collection = page.collection() %}
    {% else %}
      {% set year = "now"|date("Y") %}
      {% set collection = page.collection().dateRange('01/01/' ~ year, '12/31/' ~ year) %}
    {% endif %}

But when I call pagination number:

    {% if config.plugins.pagination.enabled and page.collection.params.pagination %}
      {% include 'partials/pagination.html.twig' with {'pagination':page.collection.params.pagination} %}
    {% endif %}

page.collection.params.pagination does not contain year param.

I could add a default param in url like this:

mydomain/events/year:<current year>

How can I define a “default” param for a page?
Thanks

I was about to tell you all about Twig defaults fallbacks and testing for defined values, but I don’t think that is your question!

So assuming your two code snippets are form the same file, it looks like you need to change the pagination parameter to use the collection variable you created above. You are using page.collection instead. Try:

{% include 'partials/pagination.html.twig' with {'pagination': collection.params.pagination} %}

The collection object has not “year” param set because it is not a parameter (I used only dateRange function). It doesn’t work even if I use setParam collection function because pagination collection is set in onCollectionProcessedevent (see pagination.php in pagination plugin).

So I try adding in frontmatter:

routes:
    default: "/mypage/year:2018"

and it works, but year is not parametric.
If I use:

routes:
    default: "/eventi/year:{{ 'now'|date('Y') }}"
frontmatter:
    process_twig: true

it doesn’t work.