Custom menu link / Custom controller

Hi! I’m working on a simple website, it has some pages, in a couple of 2-levels menu, let’s say:

  • A
    • AA
    • AB
    • AC
  • B
    • BA
    • BB
    • BC

What i’d like is that when i click on A i view directly the AA page, and when i click on B i want to see BB, so when clicking on a menu item with childs, i’d like to go to the first child page.

Is there a way to do so?

A related question is: is there a way to insert a custom menu item with a custom url and a custom controller in code, just to handle this or other situations where the simple folder->file structure is not enough?

I saw this topic, but if possible i’d like to have the first level clickable…

Thanks!

Oh!
I actually just found that (in my subtheme of quark) i can do it in this way, in a copy of templates/macros/macros.html.twig in my theme:

{% macro nav_loop(page) %}
  {% import _self as macros %}
  {% for p in page.children.visible %}
    {% set active_page = (p.active or p.activeChild) ? 'active' : '' %}
    {% if p.children.visible.count > 0 %}
      {% set child = p.children.visible|first %}
      <li>
        <a href="{{ child.url }}" class="{{ active_page }}">
          {{ p.menu }}
        </a>
        <ul>
          {{ macros.nav_loop(p) }}
        </ul>
      </li>
    {% else %}
      <li>
        <a href="{{ p.url }}" class="{{ active_page }}">
          {{ p.menu }}
        </a>
      </li>
    {% endif %}
  {% endfor %}
{% endmacro %}

Basically i added that {% set child … %} and replaced p.url with child.url in the src.

My question remains thou, at least partially.
From what i can understand the menu is built differently from theme to theme, so there’s no a common way to do something to it.
But besides the way it’s created, is there a way to tell that at a certain route / url the response have to be given from a custom controller? (let’s say that for a single page i need to do some PHP work with some service call or something like that, or create a custom redirect to other pages of the site with certain conditions…

@FrancescoQ, Welcome to the forum.

In general, it is not that handy to ask two distinct questions in one post. Would you mind splitting the post into two separate questions each with a proper title?

Since you have already answered your first question (kudos) , you may mark this thread as being ‘solved’ by clicking the ‘solution’ icon in your own reply.

I’d be happy to look into your new post…

You’re absolutely right, thanks, i opened a new post for the custom path/route controller

Thanks!