I have in my twig a link as shown below and I would like to send a lot of data (array) to a controller. How do I go about it ? Do I use params? what is the best way to handle this in your opinion? Thanks.

In my twig:


 <a href="{{ path('mymodule.send') }}">Send</a>

Routing file:

  path: '/admin/send'
        _controller: '\Drupal\mymodule\Controller\MyController::myFunction'
        _title: 'Send data'
        _permission: 'administer site configuration'
        _admin_route: TRUE

My controller where I want to send data:

class MyController extends ControllerBase {

      public function myFunction() {
  • 1
    Is the template and the controller on the same Drupal? Then I wouldn't send the data via the request, only a reference to the data in a cookie. The easiest way to implement this is setting the array as session value and removing it after the controller has fetched the data, everything else is done by Drupal/PHP.
    – 4uk4
    Commented Jun 17, 2022 at 6:43
  • What is the data that you want to pass? it is entity field values? One way to do it is to replace the link with a config form with an action button and embed it in the twig template, the form can collect the data that you want and redirect it to the controller which will give you more control of the data. If you can share more information I might be able to provide a more accurate answer. Commented Jun 17, 2022 at 11:07

1 Answer 1


A lot of data should typically be in the body of an HTTP message, so a POST with data as JSON, application/x-www-form-urlencoded, or multipart/form-data is the way.

If there is not so much data, and it is a one-dimension array, and it is acceptable that it will be logged in webserver access logs, you can use query strings.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.