How do I call a controller method from a twig template and passing arguments to it? I know I can pass variables to templates using render arrays.

$theme = 'block-AcademicDisplay';   

return array(
  '#theme' =&gt; $theme,
  '#content' =&gt; $content,
  '#url' =&gt; urlencode($url),
);


How can I pass variables and call controller methods from that template? On that template, when clicking on some buttons or links, I would like to call a controller method and pass it 2 parameters.
Passing arguments in route parameters

I think the missing part is the route that you have defined for the controller. You have to use this to generate the url:

$url = Url::fromRoute('entity.node.canonical', ['node' =&gt; 1]);


This example is for the node controller and passes the argument nid=1. The parameter names are defined in the route definition.

Passing arguments in query parameters

I've seen in one of your other posts that you want to use query parameters. This is an example for the user login:

$url = Url::fromRoute('user.login', [], ['query' =&gt; ['destination' =&gt; 'http://example.com']]);


For this to work you don't need to define a query parameter in the route. Simply inject the request as function argument (the request is always available to a controller, it's not necessary to define it in the route) and get the query parameter:

use Symfony\Component\HttpFoundation\Request;

  public function myController(Request $request) {

    $destination = $request-&gt;query-&gt;get('destination');

  }